Jeremy Thomas
Jeremy Thomas

Reputation: 6684

Redirect after uploading to S3 from rails app

I have a simple file upload field:"

<form action="<%= @post.url %>" method="post" enctype="multipart/form-data" id="new_file_tag">
    <% @post.fields.each do |name, value| %>
      <input type="hidden" name="<%= name %>" value="<%= value %>"/>
    <% end %>
    <input type="file" name="file"/>
    <input type="submit" class="btn btn-awaken btn-sm">
</form>

that I took from the S3 online docs. The only issue is that it redirects to the S3 object after upload rather than simply returning to the same page.

How can I change the form to accomplish this? I tried changing the form to rails helpers, but the upload would fail due to the automatic accept-charset="UTF-8" param.

Upvotes: 1

Views: 63

Answers (1)

Anthony L
Anthony L

Reputation: 2169

The form should contain a field for the success_action_redirect option, which has the value of the URL you would like to redirect the user to following a successful post.

https://docs.aws.amazon.com/sdkforruby/api/Aws/S3/PresignedPost.html#success_action_redirect-instance_method

Upvotes: 2

Related Questions