Setting the Content-Type in direct to S3 upload using Rails and jQuery File Upload

后端 未结 3 1480
旧时难觅i
旧时难觅i 2020-12-16 16:16

I\'ve seen many questions here on this topic but nothing I\'ve come across has worked for me, so here I am posting another...

I\'m on Ruby on Rails trying to configu

3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-16 16:56

    Replace your add block with:

          fd["Content-Type"] = data.files[0].type;  
          data.formData = fd;
          data.submit();
    

    The callback is correct, but data.formData already took the original version of fd. Just set it again with your modified fd and you should be good to go.

    Update the controller method too so you're not doing it twice:

    @s3_direct_post = S3_BUCKET.presigned_post(
                      key: "uploads/#{SecureRandom.uuid}/${filename}",
                      success_action_status: 201,
                      acl: :public_read).where(:content_type).starts_with("")
    

提交回复
热议问题