Skip to content

Instantly share code, notes, and snippets.

@eduardoromero
Created July 2, 2015 23:38
Show Gist options
  • Save eduardoromero/da56697d9f0d013657eb to your computer and use it in GitHub Desktop.
Save eduardoromero/da56697d9f0d013657eb to your computer and use it in GitHub Desktop.
Uploadcare Multiplefiles
var widget = uploadcare.Widget('[role=uploadcare-uploader]');
widget.onUploadComplete(function (response) {
if(response) {
uploadcare.loadFileGroup(response.uuid)
.done(function(fileGroup) {
// Group creation completed successfully.
var files = fileGroup.files();
$.each(files, function(i, file) {
// Wait for file uploading.
file.done(function(fileInfo) {
// i is file positon in group.
console.log(i, fileInfo);
// add | if there are more files, we'll split it on the controller
var fileFormat = fileInfo.isImage ? fileInfo.originalImageInfo.format : 'application/pdf';
if($('#nombre').val().length) {
$('#archivos').val($('#archivos').val() + '|' + fileInfo.cdnUrl);
$('#nombre').val( $('#nombre').val() + '|' + fileInfo.name);
$('#formato').val($('#formato').val() + '|' + fileFormat);
} else {
$('#archivos').val(fileInfo.cdnUrl);
$('#nombre').val(fileInfo.name);
$('#formato').val(fileFormat);
}
});
});
})
.fail(function() {
$('#archivos').val('');
$('#nombre').val('');
$('#formato').val('');
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment