Last active
August 29, 2015 14:01
-
-
Save lporras/0a9af6f3ce64120a13cd to your computer and use it in GitHub Desktop.
Plupload direct s3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Esto lo he probado con Plupload v. 2.1.1 | |
// deben cambiar la forma en que se hacen los binding de eventos de plupload, seguir el ejemplo: | |
//http://www.plupload.com/examples/core | |
// Esto debe ir en el html para poder acceder a los helpers de rails | |
App.pluploadConfig = { | |
url: "https://neufert-tmp-cdn.archdaily.net.s3.amazonaws.com/", | |
/* try replacing file_name_name: false by send_file_name: false | |
if dont work then modify plupload with: | |
... | |
line 1444 after: args.name = file.target_name || file.name; | |
if (up.settings.file_name_name == false) { | |
delete args['name'] | |
} | |
line 1600 | |
// Default settings | |
settings = { | |
runtimes: o.Runtime.order, | |
max_retries: 0, | |
chunk_size: 0, | |
multipart: true, | |
multi_selection: true, | |
file_data_name: 'file', | |
file_name_name : 'name', | |
flash_swf_url: 'js/Moxie.swf', | |
silverlight_xap_url: 'js/Moxie.xap', | |
filters: { | |
mime_types: [], | |
prevent_duplicates: false, | |
max_file_size: 0 | |
}, | |
resize: { | |
enabled: false, | |
preserve_headers: true, | |
crop: false | |
}, | |
send_chunk_number: true // whether to send chunks and chunk numbers, or total and offset bytes | |
}; | |
*/ | |
file_name_name: false, | |
multipart: true, | |
multipart_params: { | |
"filename": "#{uploader.key}", // adding this to keep consistency across the runtimes | |
utf8: true, | |
'AWSAccessKeyId': "#{uploader.aws_access_key_id}", | |
'acl': "#{uploader.acl}", | |
policy: "#{policy}", | |
signature: "#{signature}", | |
"key": "#{uploader.key}" | |
} | |
} | |
/* | |
add this line to your plupload config method | |
uploaderOptions: => | |
... | |
defaultOptions = _.extend(App.pluploadConfig, defaultOptions) | |
return defaultOptions | |
*/ | |
/* modificar el evento FileUploaded para obtener la url temporal | |
FileUploaded: (up, file, info)-> | |
image_url = "#{(App.pluploadConfig.url + App.pluploadConfig.multipart_params.filename).replace(/\$\{filename\}/, file.name)}" | |
url = this_view.$pickfilesContainer.data('url') | |
$.ajax({ | |
url: url, | |
dataType: 'json' | |
data: {file: image_url}, | |
type: 'POST', | |
success: function(data, status, xhr){ | |
hacer lo que se hacia antes en el FileUploaded, añadir nuevo item a la collection | |
} | |
}) | |
*/ | |
/* Adding gem carrierwave_direct | |
and adding include CarrierWaveDirect::Uploader in the uploader | |
and add this helpers https://gist.github.com/lporras/3696fdaa837c429fb99a*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment