maz
Has anyone uploaded to backblaze with Phoenix LiveView Upload? I think I am very close with the upload(it seems to upload the entire file but at the last moment I see this error):
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://s3.us-east-005.backblazeb2.com/the-bucket-name. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing). Status code: 501.
I’m pretty sure my CORS bucket policy is extremely liberal and I do not see why I’m getting the allow origin issue:
these are the CORS rules on the bucket:
"corsRules": [
{
"allowedHeaders": [
"*"
],
"allowedOperations": [
"s3_head",
"b2_download_file_by_id",
"b2_upload_part",
"b2_upload_file",
"s3_put",
"b2_download_file_by_name",
"s3_post",
"s3_get"
],
"allowedOrigins": [
"*"
],
"corsRuleName": "downloadFromAnyOriginWithUpload",
"exposeHeaders": [
"x-bz-content-sha1"
],
"maxAgeSeconds": 3600
}
]
and here is how I presign:
def presign_upload(entry, socket) do
uploads = socket.assigns.uploads
bucket = System.get_env("BACKBLAZE_S3_BUCKET_ID")
key = Ecto.UUID.generate() <> Path.extname(entry.client_name)
config = %{
region: System.get_env("BACKBLAZE_S3_REGION"),
access_key_id: System.get_env("BACKBLAZE_S3_APPLICATION_KEY_ID"),
secret_access_key: System.get_env("BACKBLAZE_S3_APPLICATION_KEY")
}
{:ok, fields} =
sign_form_upload(config, bucket,
key: key,
content_type: entry.client_type,
max_file_size: uploads[entry.upload_config].max_file_size,
expires_in: :timer.hours(1)
)
dbg(fields)
dbg(key)
meta = %{
uploader: "S3",
key: key,
url: "https://s3.us-east-005.backblazeb2.com/#{System.get_env("BACKBLAZE_S3_BUCKET_ID")}",
fields: fields
}
dbg(meta)
{:ok, meta, socket}
end
The presign data looks like this:
[(word_app 1.5.1) lib/word_app/file_uploads/s3_backblaze.ex:124: WordApp.FileUploads.S3Backblaze.presign_upload/2]
key #=> "ebd306d1-ca78-4bf6-95a6-44e0bb1808ac.jpg"
[(word_app 1.5.1) lib/word_app/file_uploads/s3_backblaze.ex:137: WordApp.FileUploads.S3Backblaze.presign_upload/2]
meta #=> %{
fields: %{
"acl" => "public-read",
"content-type" => "image/jpeg",
"key" => "ebd306d1-ca78-4bf6-95a6-44e0bb1808ac.jpg",
"policy" => "ewogICJleHBpcmF0aW9uIjogIjIwMjMtMDctMjBUMDU6NTY6MjYuNTk4Njg1WiIsCiAgImNvbmRpdGlvbnMiOiBbCiAgICB7ImJ1Y2tldCI6ICAiZ29zaGVuLW1lZGlhLW1haW4ifSwKICAgIFsiZXEiLCAiJGtleSIsICJlYmQzMDZkMS1jYTc4LTRiZjYtOTVhNi00NGUwYmIxODA4YWMuanBnIl0sCiAgICB7ImFjbCI6ICJwdWJsaWMtcmVhZCJ9LAogICAgWyJlcSIsICIkQ29udGVudC1UeXBlIiwgImltYWdlL2pwZWciXSwKICAgIFsiY29udGVudC1sZW5ndGgtcmFuZ2UiLCAwLCA4MDAwMDAwXSwKICAgIHsieC1hbXotc2VydmVyLXNpZGUtZW5jcnlwdGlvbiI6ICJBRVMyNTYifSwKICAgIHsieC1hbXotY3JlZGVudGlhbCI6ICIwMDU1MDgxYzYzOWQxYmYwMDAwMDAwMDAxLzIwMjMwNzIwL3VzLWVhc3QtMDA1L3MzL2F3czRfcmVxdWVzdCJ9LAogICAgeyJ4LWFtei1hbGdvcml0aG0iOiAiQVdTNC1ITUFDLVNIQTI1NiJ9LAogICAgeyJ4LWFtei1kYXRlIjogIjIwMjMwNzIwVDA1NTYyNloifQogIF0KfQo=",
"x-amz-algorithm" => "AWS4-HMAC-SHA256",
"x-amz-credential" => "0055081c639d1bf0000000001/20230720/us-east-005/s3/aws4_request",
"x-amz-date" => "20230720T055626Z",
"x-amz-server-side-encryption" => "AES256",
"x-amz-signature" => "1d16e41aef14551b9efed9aab874fa18e5e326962dcf93d6e4cdbc8cd5952182"
},
key: "ebd306d1-ca78-4bf6-95a6-44e0bb1808ac.jpg",
url: "https://s3.us-east-005.backblazeb2.com/the-bucket-name",
uploader: "S3"
}
Trending in Questions
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
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
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
Hi everyone,
I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding.
I sta...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
Other Trending Topics
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
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
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
Latest Phoenix Threads
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ai
- #ecto-query
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #metaprogramming
- #hex










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
thomas.fortes
Can you upload to B2 using something else like postman for example?
CORS is client related, so as long as the generated presigned url is correct the only code that matter is the javascript one for the S3 uploader, if you can upload from postman and not from liveview we can take a look and see what is happening.
Now from experience, if you’re using the examples from the docs for external uploads, try replacing the post with a put, most S3 compatible services that I used don’t handle presigned
POSTuploads very well unless you’re doing a multipart upload, which is a tad more complex than a simplePOSTupload.TwistingTwists
I worked with Cloudflare R2.
changing
POSTtoPUTworked for liveview uploads.maz
Changing to PUT resulted in a 403 instead of a 501.
xhr.open("PUT", url, true)TwistingTwists
Are these settings correct at your end?
TwistingTwists
Tried
PUTjust now. Getting403with most liberal bucket CORS.maz
I’ve looked for that dialog but I can’t find it. Where is it?
I found “CORS Rules” only:
metadaddy
Hi there - I don’t have any experience with Phoenix LiveView in particular, but, as Chief Technical Evangelist at Backblaze, I have worked with Backblaze B2 quite a bit! I’ll work through some of the points in this thread in the hope that it moves you a bit closer to getting presigned URLs working.
@thomas.fortes is correct in his advice to use
PUTrather thanPOST- B2 does not supportPOSTfor the S3 PutObject operation.@maz It’s revealing that the error code changed with the switch from
POSTtoPUT. When you tried to usePOST, you received a 501, “not implemented”. If you were to look at the payload in the response, it would beWith
POST, you are receiving 403, “forbidden”, which indicates that something is wrong in either the presigned URL, or the key you are using to generate it. Debugging tip - the response payload will give you more detail on what the problem actually is.CORS is a bit of a red herring here. The browser complains about the missing
Access-Control-Allow-Originheader, but it’s never going to see one on a 501 or 403 error response. Start worrying about CORS when you see 20x responses.Moving along to the code… The bad news is that
sign_form_upload(code) does not actually presign a URL. It submits aPOSTrequest with the signature and other parameters sent as form fields (AWS doc), which, as mentioned earlier, is not supported by B2. Unfortunately, changingPOSTtoPUTwon’t make it work, as the payload will still be a form submission. B2 responds with 403 since it can’t see the signature it’s expecting as either an HTTP header or a query parameter.In a presigned URL, the signature and other params are query parameters on the URL (AWS doc). Here’s a real presigned, but expired, URL for uploading the file
HelloWorld.txtto mymetadaddy-privateB2 bucket, with line breaks added so you can see the query parameters clearly:Another debugging tip - if you can capture the presigned URL, you can test it at the command line with curl, like this:
The good news… In researching this, I came upon a comment on the sign_form_upload gist pointing to a dependency-free implementation of presigned URLs. I don’t have the ability to test this, but it looks like it does the right things. Even better, it looks like the author of that code, @denvaar, has an account here and might be able to help, too.
Hope this helps - good luck getting it working!
03juan
Welcome to the forum and thanks for your great, detailed contribution!
How did you event find this? haha
metadaddy
Thanks, @03juan!
I have a Google Alert on Backblaze. It’s part of my job to help developers get up to speed with Backblaze B2
metadaddy
Oops - spotted a typo, and it looks like I can’t go back and edit my reply now. I meant to say: