Quantcast
Channel: Active questions tagged mongodb-atlas - Stack Overflow
Viewing all articles
Browse latest Browse all 271

File encryption when downloaded from GCS using nodejs

$
0
0

I'm developing a files sharing app where one can easily upload and download files. The uploaded files are stored in a bucket on google cloud storage while the metadata are stored on atlas. The files downloaded from gcs are encrypted with a '.txt' extension which is different from the inital uploaded files. I don't why this is happening, I checked the files on my bucket and they are in the right format but encrypted when downloaded.Here is a my code :

app.get('/download/:id', async (req, res) => {     const { id } = req.params;     try {        // Find doc by id and get the fileName        const document = await Document.findById(id);        if (!document || !document.fileName) {        return res.status(404).send('File not found');        }        const fileName = document.fileName;        const type = document.fileType;        console.log(type)        const [file] = await bucket.file(fileName).download();        // Set header for file download        res.setHeader('Content-Disposition', `attachment; filename=${fileName}`);        res.setHeader('Content-type', type);        // Send file as a response        res.send(file);    } catch (error) {        console.error('Error downloading the file:', error);        res.status(500).send('Error downloading the file');    }});

Viewing all articles
Browse latest Browse all 271

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>