I have an issue with Appengine (GCP) and file upload through Multer...
I'd like to store in my DB a base64 image (whatever the reason). To do so, I try to upload this image to /tmp
(apparently writable) and then encode it to base64, then store it into DB.
Locally, it works like a charm, but once deployed, it doesn't: Error: EROFS: read-only file system, mkdir '/srv/tmp'
Do you have any clue? Below my simplified code.
'use strict'
const express = require('express')
const router = new express.Router()
const multer = require('multer')
const upload = multer({ dest: 'tmp/' })
const fs = require('fs')
// APP DEPENDENCIES
const { saveHousing } = require('../models/housing.js')
/////////////////////////////////////
router.post('/', upload.single('upload'), async (req, res) => {
var img = fs.readFileSync(req.file.path).toString('base64')
const housing = { IMG: { MIME: req.file.mimetype, DATA: img } }
await saveHousing(housing)
res.redirect(`/app/dashboard`)
})
I'd like to not use Google Cloud Storage to simplify things...
App Engine allows developers to focus on what they do best: writing code. Based on Compute Engine, the App Engine flexible environment automatically scales your app up and down while also balancing the load.
Does it work if you change 'tmp/'
to '/tmp/'
?
Based on the code above, it looks like you are using a relative path instead of an absolute one. So it's not actually hitting the correct tmp
directory, and it's instead creating a new tmp
directory in your project root.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With