wlminimal

wlminimal

How to get a link(url) from uploaded image in Amazon S3

Hi!
Now I am trying to upload image using ex_aws for Amazon AWS S3

Here is my code

  def upload_file_to_S3(bucket_name, s3_filename, file_binary) do
    S3.put_object(bucket_name, s3_filename, file_binary, [{:acl, :public_read}])
    |> ExAws.request()
  end

and I hope(?) it returns with link(uploaded image url) but it didn’t return it
This is first time using ex_aws, and trying to find docs about it but can’t find it.

How can I get an upload image url like " https://s3-us-west-1.amazonaws.com/text-marketing/03da408158584cd38a51aea77754d86c.jpg"

so I can use it in html ‘a’ tag or save it to the database.

Marked As Solved

joaquinalcerro

joaquinalcerro

You can find a example here:

defmodule Epr.Services.AwsS3 do
  def put_object(bucket, filename, binary_file, opts \\ []) do
    ExAws.S3.put_object(bucket, filename, binary_file, opts)
    |> ExAws.request()
  end

  def delete_object(bucket, filename) do
    ExAws.S3.delete_object(bucket, filename)
    |> ExAws.request()
  end

  def presigned_url(
        method,
        bucket,
        filename,
        config \\ ExAws.Config.new(:s3),
        opts \\ [expires_in: 7200]
      ) do
    {:ok, url} = ExAws.S3.presigned_url(config, method, bucket, filename, opts)
    url
  end
end

Where Next?

Popular in Questions Top

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
logicmason
Hi there, I'm working through my first release with elixir/phoenix. I've built a release with distillery and found that it crashes when I...
New
dokuzbir
Hello, I am trying to convert my lists to string without losing brackets.For start i have 3 map. They look like these buyer = %{ id: ...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New

Other popular topics Top

vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
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
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
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
sergio
I couldn’t find any guides that worked well with Phoenix 1.6.0 and esbuild. I hope this helps people test the waters and eases you into t...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 49522 488
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
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
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New

We're in Beta

About us Mission Statement