s3_direct_upload icon indicating copy to clipboard operation
s3_direct_upload copied to clipboard

Additional data not sent

Open vladimirbazhanov opened this issue 9 years ago • 2 comments

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 avatar Feb 26 '15 11:02 vladimirbazhanov

@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

joseluistorres avatar Feb 26 '15 19:02 joseluistorres

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.

  1. 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 },
      ...
    
  2. In the Javascript for that view (documents.js in my case), use an additional_data element to reference the data element's value. Note that the underscore becomes a hyphen, apparently a convention for data elements (here data-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') },
      }
    );
    

mcbsys avatar Aug 21 '15 23:08 mcbsys