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

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

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
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
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
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
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

Other popular topics Top

JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 49266 226
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New

We're in Beta

About us Mission Statement