I'm working on my first react project and I have an upload button through which the user can upload a set of files. I noticed that the file upload works perfectly for all file extensions, except for .json files. I'm not quite sure why that is, can anyone take a look at my addFile function? openUploadStream is the function given by mongoDB for GridFS storage of files.
const addFile = async (req, res) => {
const { filename } = req.body
const path = "cache\\" + filename //all files are stored in the cache folder
const uploadStream = fs.createReadStream(path).
pipe(bucket.openUploadStream(filename)) //store the file as the filename}
res.status(200).json({id : uploadStream.id}) //return unique id of file in the db
}
and in the frontend I call the API using axios
await axios.post('/api/filesRoute/fs', { filename : filename })
.then((json) => {
console.log('Success uploading', filename)
raws.push(json.data.id)
})
Via Active questions tagged javascript - Stack Overflow https://ift.tt/rey8tLS
Comments
Post a Comment