CharlesO
Simulating browser-like file upload with Tesla
Please how may we upload a file as described below with Tesla?
For a self-signed certificate an extra parameter is needed,
certificate, with the public certificate in PEM format as data.
- A curl example for a self-signed certificate:
curl -F "url=https://<YOURDOMAIN.EXAMPLE>/<WEBHOOKLOCATION>" -F "certificate=@<YOURCERTIFICATE>.pem" https://api.telegram.org/bot<YOURTOKEN>/setWebhookThe
-Fmeans we’re using themultipart/form-data-type to supply the certificate
(Marvin's Marvellous Guide to All Things Webhook)
I have tried:
mp = Multipart.new()
|> Multipart.add_field("url", "https://my-sever-ip:88/bots/#{token}")
|> Multipart.add_field("certificate", "bots.pem")
|> Multipart.add_file(file, name: "bots.pem")
post("bot#{token}/setwebhook", mp)
But the operation is not successful.
Please how may I achieve the same as this : https://paperlesssolutionsltd.com.ng/bots.htm manual file upload utility using Tesla.
Thanks.
Marked As Solved
NobbZ
This curl should translate into this tesla request (I’ll take your placeholders literally):
body =
Tesla.MultiPart.new
|> MultiPart.add_field("url", "https://<YOURDOMAIN.EXAMPLE>/<WEBHOOKLOCATION>")
|> MultiPart.add_file("<YOURCERTIFICATE>.pem", name: :certificate, filename: "<YOURCERTIFICATE>.pem") # but `:filename` actually defaults to this…
Tesla.post("https://api.telegram.org/bot<YOURTOKEN>/setWebhook", body)
2
Also Liked
CharlesO
It works now.
Tesla actually works fine.
setting these two affects the post method, should have used Tesla.post instead
plug(Tesla.Middleware.Headers, [{"content-type", "application/json"}])
plug(Tesla.Middleware.BaseUrl, "https://api.telegram.org/")
body =
Multipart.new()
|> Multipart.add_field("max_connections", "100")
|> Multipart.add_field("url", "https://173.233.70.70:#{port}/bots/#{token}")
|> Multipart.add_file(file, name: :certificate, filename: name)
x = Tesla.post("https://api.telegram.org/bot#{token}/setWebhook", body)
Thanks
2
Popular in Questions
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
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
Hi all,
I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage.
I’m trying to use Postgres...
New
I will often find my self writing things similar to:
case some_value do
nil -> something()
"" -> something()
_ -> somethi...
New
Hello everybody,
usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
Credo is smart enough to check for (something like) this:
assert length(the_list) == 0
with this response:
Checking if an enum is empt...
New
Hi everyone,
I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
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
Lets say i have map like this fetching from my database
%{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => "XXX...
New
Hi!
Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New
Other popular topics
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
Hey all,
I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
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
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
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
Please see the new poll here: Which code editor or IDE do you use? (Poll) (2022 Edition)
It’s been a while since we first asked this, I...
New
Hello everyone,
Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
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 records...
New
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...
New









