HTTP PUT File/BLOB with fetch or XMLHttpRequest

0 votes
asked Sep 12, 2017 by lux

Is it possible to upload a File with fetch? I'm not talking about FormData, but I want to be the file the actual body of the HTTP PUT, and the Content-Type the correct ContentType?

If its not possible with fetch, can it be dont with the XMLHttpRequest? This code isnt working for me (event is a drop event):

fetch('/foo', {
  method: 'PUT',
  body: event.dataTransfer.files[0],


I'm specifically talking about FILE uploads. This does work if body is a Text, but not if its a FILE/BLOB!

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.
Welcome to Q&A, where you can ask questions and receive answers from other members of the community.
Website Online Counter