CharlesO

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>/setWebhook

The -F means we’re using the multipart/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

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)

Also Liked

CharlesO

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

Where Next?

Popular in Questions Top

_russellb
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
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
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 Postgres...
New
beno
I will often find my self writing things similar to: case some_value do nil -&gt; something() "" -&gt; something() _ -&gt; somethi...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
bsollish-terakeet
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
komlanvi
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
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
hariharasudhan94
Lets say i have map like this fetching from my database %{"_id" =&gt; #BSON.ObjectId&lt;58eb1a7a9ad169198c3dXXXX&gt;, "email" =&gt; "XXX...
New
svb
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 Top

chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
ovidiubadita
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
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
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
vegabook
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
vonH
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
AstonJ
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...
208 31142 143
New
saif
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
joaquinalcerro
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
Qqwy
Update: How to use the Blogs &amp; Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 126479 1222
New

We're in Beta

About us Mission Statement