Trying to get file-uploading work using Express/Node on cloudinary with no luck.I'm able to post the request,my file gets uploaded to the cloudinary server but never gets a response resulting in my request to time out.I'm using [express-file-upload][1] to send the data to cloudinary as a stream of bits and axios to post it.
My Express router API code:
const fileUpload = require("express-fileupload");
const cloudinary = require("cloudinary");
router.use(fileUpload());
cloudinary.config({
cloud_name: "xyx",
api_key: "xyxxyxxyxxyxxyx",
api_secret: "xyxxyxxyxxyxxyxxyx"
});
router.post("/upload", function(req, res, next) {
console.log(req);
var fileGettingUploaded = req.files.file.data;
cloudinary.uploader
.upload_stream({ resource_type: "raw" }, function(error, result) {
console.log(error);
console.log(result);
})
.end(fileGettingUploaded);
});
[1]: https://www.npmjs.com/package/express-fileupload
My Axios Post Request from the component
const { fileName } = this.state;
const formData = new FormData();
formData.append("file", fileName);
const url = `/api/upload`;
axiosInstance
.post(url, formData, {
headers: {
"Content-Type": fileName.type
}
})
.then(response => {
if (response.status === 200 && response.data) {
console.log(response);
}
})
.catch(error => {
console.log(error);
});
};
This results in a request which successfully uploads my file to cloudinary (I can see the uploaded file in the cloudinary's dashboard) but unable to give me a response which ideally should be a url to the uploaded file.Can anyone guide me what I'm doing wrong ?
response, i.e. not checking for 200 and if it hasdata? - Anthony