9Dave9

9Dave9

Presigned_url with post - method not allowed

Hi Peops,

SO I am trying to use the “presign_url” method on the ex_aws_s3 package - which is essentially just the “ex_aws.Auth.presign_url”.

Long story short - regardless of what url I use or options… I just cannot get this function to play ball even with postman let alone trying to send data from the browser as a form object.

[https://imgur.com/zcRA3sm](response , headers and url1)

[https://imgur.com/TNeOHsD](response , headers and url2)

my function:


  def presign_post_url(bucket_name, file_name, file_type_extension) do                                            config = % 
     config = { region: "eu-west-1" }
     ex_s3_client = ExAws.Config.new(:s3, config)
     query_params = [
        { "Content-Type", "image/jpg"},                                                                               
        {'key', "profile-pictures/" <> file_name}                                                                     
        # { "content-length-range", "10\,10000000" }#max 10MB
     ]                                                                                                             
    presign_options = [virtual_host: false, query_params: query_params]                                                                                                                                                       
    
    ExAws.S3.presigned_url(ex_s3_client, :post, "profile-pictures", file_name, presign_options)                                                                                                                               
  end

The error I get - not matter how I construct the url with bucket_name/folder-path/differents3-url-structures, I always get:

<?xml version="1.0" encoding="UTF-8"?>
<Error>
    <Code>MethodNotAllowed</Code>
    <Message>The specified method is not allowed against this resource.</Message>
    <Method>POST</Method>
    <ResourceType>OBJECT</ResourceType>
    <RequestId>D0BA0AC513BE36D6</RequestId>
    <HostId>NyzdUPLDzHnbkHzWxxcLjdGXOXkpmGOUU1KFIAPJ+vpIPEq0WWyZEerGq1xySG26qzPfKUg7l/o=</HostId>
</Error>

Cors on bucket:

<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
    <AllowedOrigin>*</AllowedOrigin>
    <AllowedMethod>GET</AllowedMethod>
    <AllowedMethod>POST</AllowedMethod>
    <AllowedMethod>PUT</AllowedMethod>
    <AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>

I am stumped, there’s another little issue - about getting the presign_url method to play nicely with “content-length-range”, as it’s not a two value keyword list.
Any help or advice would be awesome!

Most Liked

thiagomajesk

thiagomajesk

@9Dave9 Ok, I guess we are on the same boat then. I’m currently using the full 5GB limit though :sweat_smile:.
Both ex_aws and ex_aws_s3 are very raw regarding documentation on how to use the available APIs, so it can be really difficult if you don’t have previous knowledge of Amazon’s services and its idiosyncrasies (which are also not very documented sometimes).

Since this a very common use-case for file uploads, I’m surprised I couldn’t find better information. So, let’s agree to come back here if either one of us finds a better solution, deal?

VGoose

VGoose

I ran into this exact issue and came across this set of posts from AWS: Browser-Based Uploads Using POST (AWS Signature Version 4) - Amazon Simple Storage Service.

Specifically from this post: Creating an HTML Form (Using AWS Signature Version 4) - Amazon Simple Storage Service

To allow users to upload content to Amazon S3 by using their browsers (HTTP POST requests), you use HTML forms

Luckily, there’s a presigned_post util ex_aws_s3 specifically for this.

Where Next?

Popular in Questions Top

sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
tduccuong
Hi, is there any work on GUI with Elixir, that is similar to Electron/Javascript? My idea is to bundle Phoenix and BEAM into a single se...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
Fl4m3Ph03n1x
Background Let’s assume I have a typical GenServer that receives messages as requests, does some operation in a DB and returns responses....
New
LegitStack
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
New
kostonstyle
Hi all I want to have a unix time, from the current time plus 1 hour. DateTime.now + 1 hour How to get it in elixir? Thanks
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
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New

Other popular topics Top

sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
977 41022 311
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
Tee
can someone please explain to me how Enum.reduce works with maps
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
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
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
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID&lt;0.412.0&gt; terminating ** (Postgrex.Error) FATAL...
New
magnetic
Hey :wave:t3: Elixir community, I’ve been learning Elixir, and working on some side projects. My editor of choice is VSCode, and althoug...
New

We're in Beta

About us Mission Statement