I am attempting to store images in MongoDB using GridFS
The images are uploaded on the client side so I'd like to use a fetch post-call that hits a route in my express server. That route is a post request to MongoDB using GridFS
Below is the fetch call:
function postDesignImages(order) {
order.designs.map(async (design) => {
var file = new File([design.image], design.image);
console.log(file);
await fetch('http://localhost:9000/design-images', {
method: 'POST',
mode: 'cors',
body: file,
})
.then((res) => res.text())
.then((data) => {
console.log(data);
})
.catch(function (error) {
console.log('Looks like there was a problem: \n', error);
});
});
}
Next are my end points... I'm calling the last one listed:
app.use('/', indexRouter);
app.use('/orders', orderRoutes);
app.use('/users', userRoutes);
app.use('/design-images', () => {
router.post('/', (req, res) => {
console.log(req.body);
upload.single(req.body);
});
});
There are several areas that I can see being the problem.
File {name: 'blob:http://localhost:3000/8afdcdef-5426-460a-8cfa-eea24cc80856', lastModified: 1632324928209, lastModifiedDate: Wed Sep 22 2021 11:35:28 GMT-0400 (Eastern Daylight Time), webkitRelativePath: '', size: 63, …}POST /design-images - - ms - - so I guess the route was hit but then nothing happens? I don't really know what to make of that output.Any insight would be greatly appreciated. If you need any additional information feel free to ask.