Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save flyingzumwalt/7819082 to your computer and use it in GitHub Desktop.
Save flyingzumwalt/7819082 to your computer and use it in GitHub Desktop.
custom jquery-fileupload processAction: Found a simpler way to do what I wanted, but this could be useful reference for times when you want to pre-process a file when user adds it to the queue.
#
# Custom processActions
#
# Prepend to the default processQueue:
$.blueimp.fileupload.prototype.options.processQueue.unshift(
{
action: 'prepS3Upload',
# Use the action as prefix for the "@" options:
prefix: true,
fileTypes: '@',
maxFileSize: '@',
disabled: '@disablePrepS3Upload'
}
);
$.widget('blueimp.fileupload', $.blueimp.fileupload, {
# options: {},
processActions: {
prepS3Upload: (data, options) ->
dfd = $.Deferred()
file = data.files[data.index]
$.ajax({
url: data.uuid_generator_url,
type: "GET",
dataType: "json",
contentType: "application/json; charset=utf-8",
success: (response) ->
$('#fileupload').find('input[name=key]').val(response.key);
$('#fileupload').find('input[name=policy]').val(response.policy);
$('#fileupload').find('input[name=signature]').val(response.signature);
data.success_action_redirect = response.success_action_redirect
file.uuid = response.uuid
file.s3_key = response.key
dfd.resolveWith(this, [data])
,
error: (response) ->
data.files.error = true
file.error = "Could not generate UUID"
dfd.rejectWith(this, [data])
})
return dfd.promise()
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment