sid 3835 no im using module helper for

@sdnts no im using module helper for S3 in elixir
config = %{
region: @s3_region,
access_key_id: System.fetch_env!("AWS_ACCESS_KEY_ID"),
secret_access_key: System.fetch_env!("AWS_SECRET_ACCESS_KEY")
}


{:ok, fields} = SimpleS3Upload.sign_form_upload(config, @s3_bucket,
key: filename(entry),
content_type: entry.client_type,
max_file_size: socket.assigns.uploads[entry.upload_config].max_file_size,
expires_in: :timer.hours(1)
)

metadata = %{
uploader: "S3",
key: filename(entry),
url: @s3_url,
fields: fields
}
config = %{
region: @s3_region,
access_key_id: System.fetch_env!("AWS_ACCESS_KEY_ID"),
secret_access_key: System.fetch_env!("AWS_SECRET_ACCESS_KEY")
}


{:ok, fields} = SimpleS3Upload.sign_form_upload(config, @s3_bucket,
key: filename(entry),
content_type: entry.client_type,
max_file_size: socket.assigns.uploads[entry.upload_config].max_file_size,
expires_in: :timer.hours(1)
)

metadata = %{
uploader: "S3",
key: filename(entry),
url: @s3_url,
fields: fields
}
i thought that it will work as well with the s3 compat api, it sends
xhr.open("POST", url, true)
xhr.send(formData)
xhr.open("POST", url, true)
xhr.send(formData)
request
4 Replies
Sid
Sid3y ago
Well if you're talking to R2 from your own backend, then: 1. Setting up a CORS config on R2's side will not do anything. CORS is a browser-only thing. 2. You'll have to return CORS headers from your Elixir server to make sure the browser is able to talk to it So really, your issue has nothing to do with R2
noctate
noctateOP3y ago
but i think this module should handle that stuff, it does for s3, I believe? https://gist.github.com/chrismccord/37862f1f8b1f5148644b75d20d1cb073 this is the way to do it in liveview which is a weird hybrid of client and server in phoenix, how can I make sure that headers are set correctly?
Gist
Simple, dependency-free S3 Form Upload using HTTP POST sigv4
Simple, dependency-free S3 Form Upload using HTTP POST sigv4 - simple_s3_upload.ex
Sid
Sid3y ago
I'm not really familiar with Elixir, and especially because you say there's isomorphic stuff happening: I'd first make sure where the R2 request is happening. Logic would dictate that it is happening from your server (otherwise you'd be shipping credentials client-side). So it's Browser <-> Your server <-> R2. Because your browser is talking to your server, you are responsible for setting the right CORS headers
noctate
noctateOP3y ago
hmm but again i dont understand why with aws and the same code, same cors policies, I can see in the RESPONSE headers I can clearly see the 'Access-Control-Allow-Origin' header, but not with the r2 api turns out this module was not the right fit for the job, I have used ex_aws s3 library and it's working! Thanks, you help me get on the right track!

Did you find this page helpful?