0

I would like to do create a tempermonkey script that would download a file on a site without bothering the user with saving it on the disk. So the file would be stored in a variable, which the script would be able to use to upload that file to my remote server.

Is it possible to do in browser javascript?

  • Diagram:

Diagram

aviya.developer
  • 3,343
  • 2
  • 15
  • 41
Linux_cat
  • 45
  • 12

1 Answers1

3

One option would be to download the file as a blob using fetch:

async function upload() {
  const res = await fetch('https://example.com/download-endpoint')
  const blob = await res.blob()

  fetch('https://example.com/upload-endpoint', {
    method: 'POST',
    headers: {
      'Content-Type': blob.type
    },
    body: blob
  })
}

Pavlo
  • 43,301
  • 14
  • 77
  • 113