Using Twitter as an example: Twitter has an endpoint for uploading file data. https://developer.twitter.com/en/docs/media/upload-media/api-reference/post-media-upload-append
Can anyone provide an example of a real HTTP message containing, for example, image file data, showing how it is supposed to be structured? I’m fairly sure Twitter’s documentation is nonsense, as their “example request” is the following:
POST https://upload.twitter.com/1.1/media/upload.json?command=APPEND&media_id=123&segment_index=2&media_data=123
Is the media_data really supposed to go in the URL? What if you have raw binary media data? Would it go in the body? How is the REST service to know how the data is encoded?
2
Answers
You’re looking at the chunked uploader – it’s intended for sending large files, breaking them into chunks, so a network failure doesn’t mean you have to re-upload a 100 MB .mp4. It is, as a result, fairly complicated. (Side note: The file data goes in the request body, not the URL as a GET parameter… as indicated by “Requests should be multipart/form-data POST format.”)
There’s a far less complicated unchunked uploader that’ll be easier to work with if you’re just uploading a regular old image.
All of this gets a lot easier if you use one of Twitter’s recommended libraries for your language.
to upload a file, you need to send it in a form, in node.js server you save accept the incoming file using formidable.
You can also use express-fileupload or multer