'Streaming file from S3 using express, NoSuchKey error after file already loaded in browser

I'm attempting to stream images and videos from my S3 bucket to my browser by piping the stream through express. I've got the stream working, but even though it works in the browser I'm still getting NoSuchKey errors every time I make the request.

app.get("/:key", async (req, res) => {
s3.getObject({Bucket: "my-bucket", Key: req.params.key}, (err, data) => {
    if (err){
        console.log("error: ", err)
    }
    else {
        console.log("data: ", data)
        res.set('Content-Type', data.ContentType)
        res.set('Content-Length', data.ContentLength)
        res.status(200)
        let rs = require('stream').Readable.from(data.Body)
        rs.pipe(res)
    }
    
})

// try {
//     s3.getObject({Bucket: "my-bucket", Key: req.params.key}).promise().then(
//         (data) => {
//             console.log("data: ", data)
//             res.set('Content-Type', data.ContentType)
//             res.set('Content-Length', data.ContentLength)
//             res.status(200)
//             let rs = require('stream').Readable.from(data.Body)
//             rs.pipe(res)
//         },
//         (err) => {
//             console.log("error: ", err)
//         }
//     )
    
// }
// catch(err){
//     console.log(err)
// }
})

I've tried using promises with the commented out code with the same result.

output:

error:  NoSuchKey: The specified key does not exist.  
    at Request.extractError (C:\my_path\node_modules\aws-sdk\lib\services\s3.js:710:35)  
    ...


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source