It seems like you tried to write to a local file which is impossible in the serverless runtime as everything is read only since the entire file system would be discarded as soon as the function returns. Can you share more about what you’re trying to do?
I am using Express, Multer, and Cloudinary. In my local environment, everything works fine, but in the deployment mode, I am encountering issues. I would like to know what the solution for this type of error might be. I am trying to resolve it, but I may not be doing it the right way, so I am looking for suggestions or a direct solution to this problem.
As @versecafe rightly asked, could you share more about your project? The tech stack is a great start but it would help us help you find a solution. What are you building? When do you see this error?
From the error, it looks like there may be an issue with the path /var/task/src/uploads/. If it works on local, it might be how you’ve configured your build. Sharing some relevant docs:
If you have Multer writing anything to the local FS as part of the upload process say Req → Fs → Cloudinary It will fail, would also like to give a warning any upload over 4.5 MB will also fail due to hitting body size limits and you may want to look into sending pre-signed upload URLs for something like S3 or cloudinaries equivalent
@pawlean, thank you very much for the welcome. I am building an ecommerce project that requires uploading images of products. The problem or error arises when I try to upload a new product with all its features, description, and a photo of the product. However, it does not allow me to upload images, possibly due to an issue with Multer or Cloudinary. It might also be related to some limitation with Vercel. This issue occurs on the backend side. As I mentioned earlier, it works locally. I’ve checked the routing, and everything seems fine. Here is the Multer code I am implementing.
This section is impossible to do in a serverless runtime multer.diskStorage cannot be used as the entire storage is thrown out as soon as the function returns and as such is read only, you need to parse and then upload without writing to the FS
Any suggestions on this? I was considering using multer-storage-cloudinary, but I noticed that its version is deprecated. If you have a more up-to-date solution, I would greatly appreciate it.