Ruo
Ruo

Reputation: 127

file upload won't upload .Json file

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)
        })

Upvotes: 0

Views: 472

Answers (0)

Related Questions