Google Cloud Functions 部署:EROFS:只读文件系统

Google Clould Functions deploy: EROFS: read-only file system

我正在尝试将我的 api 部署到 Google Cloud Functions,我得到了这个:

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)

Cloud Functions 运行时中的所有内容都是只读的,除了 os.tmpdir()(很可能是 /tmp,但您不应该这样假设)。如果您有任何代码(例如在 api/user.js 中)试图在其他地方写入,它将出错。

python 也有同样的问题,但为了清楚起见,将其放在一起。我的错误-

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'

获取临时目录如下(通常/tmp):

import tempfile
tmpdir = tempfile.gettempdir()

Google 文档可以是 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.