jimmywarting / StreamSaver.js

StreamSaver writes stream to the filesystem directly asynchronous
https://jimmywarting.github.io/StreamSaver.js/example.html
MIT License
3.95k stars 413 forks source link

Zip Files in Self Hosted MITM don't seem to work #304

Closed rsmithbotkeeper closed 1 year ago

rsmithbotkeeper commented 1 year ago

Hello! I am using presigned urls from S3 and downloading a zip file. Locally when I don use the self hosted MITM files this works just fine but in my upper envs the zip files download but are empty/corrupted (as if the data doesn't actually download) the headers are all the same just confused why its not working

the normal non zip files are working fine its just zip files

here is the function

try {
    if (process.env.REACT_APP_NODE_ENV !== 'localhost') streamsaver.mitm = '/static/mitm.html'
    const fileStream = streamsaver.createWriteStream(fileName)
    return fetch(presignedUrl).then((res) => {
      const readableStream = res.body

      if (window.WritableStream && readableStream.pipeTo) {
        return readableStream.pipeTo(fileStream).then()
      }

      window.writer = fileStream.getWriter()

      const reader = res.body.getReader()
      const pump = () => reader.read().then((res) => (res.done ? window.writer.close() : window.writer.write(res.value).then(pump)))

      pump()
    })
  } catch (error) {
    logger.error('error getting download file', error)
  }

this is the error I get when trying to open the zip file

Screen Shot 2023-02-06 at 10 23 39 PM

another note im hosting the files in the static folder and both the MITM html and ws.js are in there

rsmithbotkeeper commented 1 year ago

turned out to be a flag was off causing this to be expecting a presigned url but got a blob instead this is all good! sorry!