s3_direct_upload
s3_direct_upload copied to clipboard
Additional data not sent
Hi!
I have Rails-based app where I want to upload file and I have noticed a problem with sending additional data within callback query. Here is my code:
$('#s3-uploader').S3Uploader({
remove_completed_progress_bar: false,
additional_data: {
node_id: '123'
}
});
also I have a form:
= s3_uploader_form callback_url: attachments_url,
callback_param: 'attachment[url]',
id: 's3-uploader',
key: "big_attachments/#{SecureRandom.hex}/${filename}",
key_starts_with: 'big_attachments/',
data: {node_in_editor: '123'}
When file uploaded and I look to callback query params I sometimes see node_id
param, sometimes node_in_editor
but it disapears after I reload page and try again...
I really have no idea how to debug this problem, please help me with this)
Thanks!
@vladimirbazhanov I'm learning to use this wrapper, it worked for me without adding the data in the helper s3_uploader_form but instead using the additional_data: in the JS. I'm debugging using Chrome Tools in the "sources" tab, select s3_direct_upload and click on line 79
This is tricky but I think I found a combination that works. In my case, I want to supply a message_id so that the document I upload can be attached to that message.
-
In the form, supply the message_id in the
data
element:<%= s3_uploader_form callback_url: documents_url, id: "s3_uploader", callback_param: "document[direct_upload_url]", data: { message_id: @message.id }, ...
-
In the Javascript for that view (
documents.js
in my case), use anadditional_data
element to reference thedata
element's value. Note that the underscore becomes a hyphen, apparently a convention for data elements (heredata-message-id
when viewed in the HTML):$('#s3_uploader').S3Uploader( { remove_completed_progress_bar: false, progress_bar_target: $('#uploads_container'), additional_data: { "document[message_id]": $('#s3_uploader').data('message-id') }, } );