The send_location_to_server.py example works flawlessly on my Pico LTE using Webhook.site. Now I would like to send a file via HTTP. I can do this easily with the requests library on a PC to Webhook.site. How can I do it on my Pico LTE?
I tried the post_from_file() function in post.py but I think I misunderstood the purpose of that function - I think it assumes I have json or something of the post header, body, etc in that file - is that right? So is there a way to send a csv file via HTTP?
And follow-up question: I understand I could just read the file and post it as text. I was hoping to reduce memory use. Is that possible or will whatever solution is available with the PicoLTE libraries just upload the whole file to memory anyway?
I never figured out how to send a file, I’ve been sending long strings instead and parsing it on the server that receives it. Follow up question: is there a built in way to send json instead of just strings? Or do I need to hack the SDK some more?
It’s a long time since I last read the code. So, after looking into it very shortly, I see that post_from_file might help you. According to the documentation of AT+QHTTPPOSTFILE, the command is used send HTTP body OR body+header depending on the request_header flag.
If <request_header> is set to 0, the file in file system will be post body. If <request_header> is set to 1, the file in file system will be post header and body.
It looks like the code did not implement setting the header to 1, but that’s all fine. You should be able to set this to the CSV you want to send, and set-up Content-Type: text/csv header for HTTP request with set_custom_header. Or just use set_content_type() function to define it as “text/plain” if your server does not need the CSV specification. a I would even try to set the Content-Length: <csv bytes> to make sure that communication is robust – not sure if that’d work on Quectel tho.
The only thing I cannot foresee with this setup is understanding what a filesystem refers to. I’m suspicious that the file should exist in Quectel’s filesystem (not in Pico LTE’s). If so, use upload_file_to_modem() it to send the file from Pico to Quectel.
I cannot help you further since I don’t have a device, but that should work out. Don’t forget that sending a file through HTTP is just adding it to the body and specifying the file type in the header. Please share your experimentation with us. An example file would be super awesome to the repository.