Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Appengine - tmp/ filesytem error when uploading a file

Tags:

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...

like image 875
charnould Avatar asked Jan 29 '19 19:01

charnould


People also ask

What is App Engine flexible environment?

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.


1 Answers

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.

like image 54
Alex Avatar answered Sep 19 '22 14:09

Alex