0

I am able currently only able to upload a file and a JSON separately using JS fetch but have no clue how to do both in the same request.

This is how I upload a file:

  fetch(host+`/upload`, {
    method: 'POST',
    body: foo
  })

This is how I sent a JSON:

fetch(host+`/upload`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({"foo": bar,})
  })

How do I do both in the same request?

Denzyl
  • 145
  • 6
  • 1
    If you want to send a file, the content type in the headers could be something like "application/octet-stream" and for a json it is "application/json". Check out if this helps: https://stackoverflow.com/questions/9081079/rest-http-post-multipart-with-json – Costa Jun 23 '21 at 14:49

0 Answers0