Val K, thank you! All work.
If somebody want to upload files using one button use it:
controller:
def loadDocs():
documents = request.vars
for key in documents:
doc = documents[key]
db_app.doc_images.insert(person='{0} {1}
{2}'.format(session.abit_f,session.abit_i,session.abit_o),file=db_app.doc_images.file.store(doc,doc.filename))
return doc.filename
view:
<button id="btnOne" class="col-sm-12 col-lg-4 good-btn"
style="margin-bottom: 10px;"><div class="my-btn-conteiner"><span
class="glyphicon glyphicon-paperclip"></span><p
class="p-btn">Прикрепить</p></div></button>
<input type="file" id="openDialog" multiple="multiple"
style="display:none"/>
<script>
$(function() {
var files;
function showLoadDocsInfo(data) {
console.log('In showLoadDocsInfo');
console.log(data);
}
$('#openDialog').on('change', function () {
files = this.files;
console.log('files = '+files);
if (typeof files == 'undefined' ) return;
var data = new FormData();
$.each( files, function(key, value ) {
data.append(key, value);
});
console.log('data = '+data);
jQuery.ajax({
type: "POST",
url: "loadDocs",
data: data,
//enctype: 'multipart/form-data',
cache: false,
processData: false,
contentType: false,
success: showLoadDocsInfo,
error: function(data){
console.log("error");
console.log(data);
}
});
});
$('#btnOne').on('click', function() {
$('#openDialog').click();
});
});
</script>
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.