silverdr

silverdr

Downloading with :httpc request questions

Apparently in Elixir the most direct (in the “dependencies-free” sense) way of downloading remote file is to use

https://www.erlang.org/doc/man/httpc.html#request-5

At least I haven’t found anything else so far. That seems OK as the task at hand is nothing complex. Just GET a remote file over http(s) and save it to a local one:

:httpc.request(:get, {'https://my.file.server.net/filename', []}, [timeout: 5000], [stream: 'local_file'])

seems to do the job, but:

  • file is “binary” (in the general, not Elixir meaning) yet I see no difference between body_format: :binary and the default (string). Is there any?

  • more importantly I can’t fathom how to make the downloaded file overwrite existing one at the local destination path. New file gets appended to the existing one instead of overwriting it. Is there any Erlang voodoo I am missing here or do I have to handle this myself?

  • and the most important question is: is there a way to limit the response size. I mean it’s great that I can limit the time of the request (timeout) so that this doesn’t hang there forever but what if for some reason I get the output of /dev/zero for example instead of what I am expecting. IOW I don’t would like to store files only up to certain length (byte count). Any clues?

First Post!

silverdr

silverdr

There’s also:

which seems to be doing almost all that’d be needed in my case but it’s a few more dependencies pulled for something that feels like it should be much simpler

Where Next?

Popular in Questions 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
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
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
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
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
johnnyicon
Hi all, I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I'm trying to use Postg...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> someth...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
wernerlaude
In AR this is so simple @articles = current_user.articles How to do in Ecto? def index(conn, _params) do current_user = conn.assig...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New

Other popular topics Top

yurko
Here are few pieces of (common) Linux knowledge that we use for reasonably small one server apps. We use Ubuntu but this should work for ...
New
shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
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
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
William
I would like to know that is there any online source for learning Phoenix Framework for building E-Commerce Store? Any advantage on build...
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
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
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
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New

We're in Beta

About us Mission Statement