0

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?

  • 1
    Possible duplicate of [How does HTTP file upload work?](https://stackoverflow.com/questions/8659808/how-does-http-file-upload-work) – Nick May 29 '19 at 01:58
  • Yes you are right, on second consideration, that does answer my question. This is a duplicate. – CircuitScholar May 29 '19 at 02:56

2 Answers2

0

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.

ceejayoz
  • 176,543
  • 40
  • 303
  • 368
  • I understand that, but I'm leery of the simple image endpoint because Twitter seems to hint they will deprecate it in the future; They are strongly pushing the chunked uploader for all use cases. Also, their node.js library is two-and-a-half years outdated and extremely bare-bones. Even with it, I would not know where to begin as far as how to pass image file data to the provided `postMedia` function, as it just takes a "params" argument with no guidance at all as to what it should contain. – CircuitScholar May 29 '19 at 02:11
  • 1
    I've seen no indications Twitter will deprecate the unchunked endpoint, and would suggest tackling that problem *when* it's a problem (with a lengthy deprecation period, given the number of third party clients out there) instead of speculatively. – ceejayoz May 29 '19 at 02:25
0

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

Vinil Prabhu
  • 1,279
  • 1
  • 10
  • 22