I have a react app where I use react-dropzone-component
. When I drop images to it, I send a POST request for each image (in future bulk upload, but one step a time) on a firebase function to process the file and save it in functions local tmp storage. When ever I use remote url, it always fails on cors
with Access-Control-Allow-Origin
http://localhost:3000
. But when I serve the functions locally and use localhost url for the upload function it works.
Express functions for upload:
const storage = multer.diskStorage({
destination: './tmp/',
filename: (req, file, cb) => {
cb(null, file.originalname);
}
});
const upload = multer({ storage });
export default () => {
const app = express();
app.use(cors(), upload.single('file'), (req, res) => {
if (req.file) {
res.send({ path: req.file.path });
} else {
res.send({ responseText: 'no file' });
}
});
return app;
};
Also tried to use cors({ origin: true })
and cors({ origin: 'http://localhost:3000' })
, but no luck.
The response I get from the function is 'no file'
and when I put console.log
in it the file is null
. On localhost
it works as expected.