jxxcarlson

jxxcarlson

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

Showing Posts 1 to 10

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.

jxxcarlson

jxxcarlson OP

Thanks, it indeed seems to be the case that one cannot set the ACL this way. Do you know if it i possible to set the bucket parameters so that uploaded files are automatically publicly readable?

What i am trying to accomplish is to allow users of my app to upload images that will be publicly readable.

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
)
aphillipo

aphillipo

This is really cool - so you don’t actually need to make a single thing public and I can get MUX.com to read a signed URL when making video for me. Will try this method, thanks!

ngocling_ng

ngocling_ng

Change your query_params to this:

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

maz

This Works For Me, thanks.

polypush135

polypush135

Thank you good sir.

maz

maz

I’ve been trying to set the "Content-Disposition" key to attachment via the query_params for the presigned_url in this scenario, but it doesn’t seem to be “taking”. Is there any way to do this here, that is via the ex_aws_s3 upload?

        query_params = [
        ....
          # so the browser will download this as a file
          {"ContentDisposition", "attachment"},
        ....
        ]
PJUllrich

PJUllrich

Author of Building Table Views with Phoenix LiveView

I managed to generate a S3 presigned download URL which behaves like a file download by setting the response-content-disposition: "attachment" header:

config = ExAws.Config.new(:s3, region: get_region())
opts = [query_params: [{"response-content-disposition", "attachment; filename=#{file.filename}"}]]

{:ok, url} = ExAws.S3.presigned_url(config, :get, get_bucket(), file_path, opts)

If you redirect the user to this URL in your controller, it will automatically download and rename the file to file.filename.

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
Cxx-mlr
I’m working on a small exercise involving update_in/3, and I came up with this solution: data = %{ name: "Periodic Table", category:...
New
ChrisAmelia
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication): toke...
New
dillonoconnor
Is there any way to avoid the Hologram compiler running when using iex? It seems like the front-end code could potentially be disregarded...
New
thiagogsr
** (ArgumentError) expected :max_attempts to be a positive integer, got: {:@, [line: 10, column: 19], [{:max_attempts, [line: 10, column:...
New
unaware8150
Hello folks! So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews