I'm trying to deploy my api to Google Cloud Functions, and I'm getting this:
EROFS: read-only file system, mkdir '/user_code/uploads'
⚠ functions[post]: Deployment error. Function load error:
Code in file index.js can't be loaded. Is there a syntax error in your code?
Detailed stack trace: Error: EROFS: read-only file system, mkdir '/user_code/uploads'
at Error (native)
at Object.fs.mkdirSync (fs.js:932:18)
at Function.sync (/user_code/node_modules/multer/node_modules/mkdirp/index.js:71:13)
at new DiskStorage (/user_code/node_modules/multer/storage/disk.js:21:12)
at module.exports (/user_code/node_modules/multer/storage/disk.js:65:10)
at new Multer (/user_code/node_modules/multer/index.js:15:20)
at multer (/user_code/node_modules/multer/index.js:95:12)
at Object.<anonymous> (/user_code/api/user.js:105:46)
at Module._compile (module.js:577:32)
at Object.Module._extensions..js (module.js:586:10)
Everything in the Cloud Functions runtime is read-only except for os.tmpdir()
(which is likely going to be /tmp
, but you shouldn't assume that). If you have any code (in api/user.js
for example) that attempt to write anywhere else, it'll error.
Same issue for python, but putting this for clarity. My error -
File "/env/local/lib/python3.7/site-packages/google/cloud/storage/blob.py", line 753, in download_to_filename
with open(filename, "wb") as file_obj:
OSError: [Errno 30] Read-only file system: 'testFile.zip'
Get the temp directory as follows (usually /tmp
):
import tempfile
tmpdir = tempfile.gettempdir()
Googles documentation can be found here.
While Cloud Storage is the recommended solution for reading and writing files in App Engine, if your app only needs to write temporary files, you can use standard Python 3.7 methods to write files to a directory named /tmp.
All files in this directory are stored in the instance's RAM, therefore writing to /tmp takes up system memory. In addition, files in the /tmp directory are only available to the app instance that created the files. When the instance is deleted, the temporary files are deleted.
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