I was trying to build a CLI tool in Crystal to use send-anywhere.com
from the command line.
Sending multipart is not builtin in Crystal but before writing my own I thought I would try to use cURL to see how exactly I should make it but I can't even get it to work with cURL!
The issue is that when sending more than one file with cURL their server only sees 1 file incoming, they do see the total length but fail at 50% since they were only expecting one file.
What kills me is that it works in the browser, I have the network inspector open and I fail to see the difference with my cURL request. I've tried setting the Expect header to 100-continue, I've compared them but I fail to see what could make it work with the browser and not curl.
Here's the command I tried with cURL all with the same result, the server ends up seeing only 1 file incoming not 2.
For testing purposes I was using a few copies of a generic LICENSE file.
curl -F file1=@LICENSE -F file2=@LICENSE1 https://...their.weblink...
I've seen in the inspector that Chrome names the file name="file[]" in Content-Disposition, so I tried it myself (same result):
curl -F file[]=@LICENSE -F file[]=@LICENSE1 https://...their.weblink...
I also tried these 2 commands using -H "Expect: 100-continue"
with same result.
At this point I got mad and thought I'd try it myself, maybe cURL can't do it properly (highly unlikely imo, much higher chance that I'm doing something wrong).
So before writing it from scratch I tried an implementation that was used by a Telegram bot see here: https://github.com/hangyas/TelegramBot/blob/b3fcbbb621bd669bbafe9f3e91364702d06d1e10/src/TelegramBot/http_client_multipart.cr
It's pretty straightforward but I still get the same issue. Only the first file is recognized.
Note: everything works fine with both cURL and the Crystal implementation when sending only one file.
I'm going crazy, what's the difference between the browser which works and the other two? What am I not seeing?
I'm not looking for an implementation but just for someone to point out what I missed that would make multiple files recognized correctly?