I excuse myself right here... I am a HTTP noob... but I need to create a python script that takes a file and uploads it to a server in chunks including additional data.
EDIT: It's only one file that I want to upload... but in chunks
So I started researching and came across pycurl
which seems to be pretty complicated. So I went on to requests
which looks really nice and intuitive.
And basically I got it working in parts... but... not all of it combined :)
I've seen that I can use generators to provide chunks of my data. That's awesome! But I also need to send (sorry... my vocabulary when it comes to that kind of stuff is very limited) multipart boundaries??? Other fields that contain JSON information...
So my requests should look something like that:
POST / HTTP/1.1
Host: some server
Content-Type: multipart/form-data;
Connection: Keep Alive
Transfer-Encoding: chunked
--boundary
Content-Disposition: form-data; name="Name of my field"
Content-Type: application/JSON; charset=utf-8
Content-Transfer-Encoding: 8bit
{"Some" : "content", "in" : "here"}
--boundary
Content-Disposition: form-data; name="My File"
Content-Type: audio/mpeg
Content-Transfer-Encoding: binary
... chunk 1 ....
--boundary
Content-Disposition: form-data; name="My File"
Content-Type: audio/mpeg
Content-Transfer-Encoding: binary
... chunk 2 ....
and so on...
I figured that I can create the chunked upload using a generator. And I also figured that I can create the non-file-boundaries by using the file=
option.
But the problem is that I can't use both :( And also when using my genrator I can't define f.e. the Content-Type
of my chunks, nor a name...
Again... sorry for my bad vocabulary :)
Any help is very much appreciated