jxxcarlson

jxxcarlson

Presigned URLs with ExAws

Hello! I am using ExAws and the code below to make a presigned request for uploading image files to Amazon S3. All is well except that the permissions on the uploaded file are not being set to public-read:

 def make_presigned_url(bucket, path, mime_type) do
    query_params = [{"ContentType", mime_type}, {"ACL", "public-read"}]
    presign_options = [query_params: query_params]
    {:ok, presigned_url} = ExAws.Config.new(:s3) 
        |> ExAws.S3.presigned_url(:put, bucket, path, presign_options)
    presigned_url 
 end

Do you see any other mistakes?

PS. Here is .typical presigned url produced with the above:

https://s3.amazonaws.com/noteimages/jxxcarlson/carr_fire_2.jpg?ACL=public-read&ContentType=image%2Fjpeg&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAJQYJYCIAWH6DGHIQ%2F20180809%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20180809T045031Z&X-Amz-Expires=3600&X-Amz-SignedHeaders=host&X-Amz-Signature=e6e620f563606cfea26340c0f8f402bad35a5c50a841b25d5168bccf52f6da15

Marked As Solved

wmnnd

wmnnd

I think this might simply not be possible. If you take a look at the AWS Java SDK docs, you can see that only a handful of parameters that would usually be sent as headers are supported (there is setContentMd5, setContentType, etc - but not setACL).
Also check out this GitHub issue with two possible workarounds.

Also Liked

tajchumber

tajchumber

I got it to work, it was very simple in the end!
here’s the code

ExAws.Config.new(:s3)
|> ExAws.S3.presigned_url(
  :get,
  bucked_name,
  filename
)
ngocling_ng

ngocling_ng

Change your query_params to this:

query_params = [
      {"ContentType", type},
      {"x-amz-acl", "public-read"}
 ]

Last Post!

maz

maz

Thanks for the tip!

Where Next?

Popular in Questions Top

Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New

Other popular topics Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

We're in Beta

About us Mission Statement