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

Pau*_*ito 4 javascript multer google-cloud-functions

我正在尝试将api部署到Google Cloud Functions,并且得到以下信息:

EROFS:只读文件系统,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)
Run Code Online (Sandbox Code Playgroud)

Dou*_*son 8

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


Con*_*nor 7

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'
Run Code Online (Sandbox Code Playgroud)

可以在此处找到Google 的文档。

虽然 Cloud Storage 是在 App Engine 中读取和写入文件的推荐解决方案,但如果您的应用程序只需要写入临时文件,您可以使用标准 Python 3.7 方法将文件写入名为 /tmp 的目录。

此目录中的所有文件都存储在实例的 RAM 中,因此写入 /tmp 会占用系统内存。此外,/tmp 目录中的文件仅对创建这些文件的应用程序实例可用。当实例被删除时,临时文件也被删除。

  • 您先生绝对是一个传奇人物。 (2认同)