Hi. I am building a back end for a mobile app and I would like to have the app be able to upload files directly to s3. I am following this documentation
http://shrinerb.com/rdoc/files/doc/direct_s3_md.html and I need to use the static strategy (strategy B).
The back end is in sinatra.
So I have done this.
require "shrine/storage/s3"
get '/picture/upload' do
s3_options = {
access_key_id: Config.AWS_ACCESS_KEY_ID,
secret_access_key: Config.AWS_SECRET_ACCESS_KEY,
region: Config.AWS_REGION,
bucket: Config.AWS_UPLOADS_BUCKET,
}
Shrine.storages = {
cache: Shrine::Storage::S3.new(prefix: "cache", **s3_options),
store: Shrine::Storage::S3.new(prefix: "store", **s3_options),
}
content_type :html
erb :picture_upload
end
I just copied and pasted the view as well
<%
presign = Shrine.storages[:cache].presign SecureRandom.hex,
success_action_redirect: '/picture/upload/success',
allow_any: ['utf8', 'authenticity_token']
%>
<form action="<%= presign.url %>" method="post" enctype="multipart/form-data">
<input type="file" name="file">
<% presign.fields.each do |name, value| %>
<input type="hidden" name="<%= name %>" value="<%= value %>">
<% end %>
<input type="submit" value="Upload">
</form>
So I get the form but when I submit I get the following error from amazon.
<Error>
<Code>InvalidArgument</Code>
<Message>
Bucket POST must contain a field named 'key'. If it is specified, please check the order of the fields.
</Message>
<ArgumentName>key</ArgumentName>
<ArgumentValue/>
<RequestId>33417C217DC288E2</RequestId>
<HostId>
aMIzKulrJwQgbGn8cMWmXJ0OZUbX2ypRg+PJe0XAqEmJ8cHOazj14ctTztiww5EN5AMXx2N2+aE=
</HostId>
</Error>
I really need to do the static method because the client is using nativescript and it doesn't support s3 very well.
What can do to make this work?
Thanks.