Majd

Majd

Suggestions for Image Upload in JSON API

Hi, I’m building a REST API using Phoenix, We have a product schema that is related to many images.

We first started thinking more about image uploading while developing the product APIs, we firstly wanted to do a basic multipart upload along with the product data, with leveraging Waffle and ecto to upload to an S3 compatible storage.

However, we were a bit influenced by Phoenix’s LiveView way of handling uploads. Briefly, it uploads files to a tmp location before submitting the other data in the form. It leverages a GenServer that deletes those files if not consumed by the LiveView. This way however, also leverages that the LiveView is an active socket, and all the data needed about files, locations can be communicated through the socket.

And finally, my question is, do you guys recommend replicating this method of uploading images in a JSON API Phoenix app? Given that the primary consumer of this API is a mobile app, and if done, we’ll be mostly be leveraging long polling to maintain a connection with the server and speaking with the GenServer that’ll delete our temp files if not consumed.

Most Liked

tfwright

tfwright

If you are uploading to S3, I would recommend uploading directly there in the client, and then having the client send just the metadata to your API. On the server, you can handle “promoting” the file on S3 as part of a scheduled/async task.

Where Next?

Popular in Questions Top

jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
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
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 131117 1222
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31586 112
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New

We're in Beta

About us Mission Statement