Home > Blockchain >  How to upload files to read-only file system on cyclic.sh?
How to upload files to read-only file system on cyclic.sh?

Time:11-29

Unable to upload files from my UI when running express server on cyclic.sh.

The same code was working on heroku, using the mkdirp module. https://www.npmjs.com/package/mkdirp

Getting the following error:

2022-11-23 14:04:30.748: /var/task/node_modules/multer/node_modules/mkdirp/index.js:91
                    throw err0;
                    ^

Error: EROFS: read-only file system, mkdir '/var/task/public/uploads'
    at Object.mkdirSync (node:fs:1349:3)
    at sync (/var/task/node_modules/multer/node_modules/mkdirp/index.js:72:13)
    at Function.sync (/var/task/node_modules/multer/node_modules/mkdirp/index.js:78:24)
    at new DiskStorage (/var/task/node_modules/multer/storage/disk.js:21:12)
    at module.exports (/var/task/node_modules/multer/storage/disk.js:65:10)
    at new Multer (/var/task/node_modules/multer/index.js:15:20)
    at multer (/var/task/node_modules/multer/index.js:95:12)
    at Object.<anonymous> (/var/task/routes/cards.js:29:16)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/var/task/server.js:40:20)
    at Module._compile (node:internal/modules/cjs/loader:1105:14) {
  errno: -30,
  syscall: 'mkdir',
  code: 'EROFS',
  path: '/var/task/public/uploads'
}
2022-11-23 14:04:30.765: 

ERROR: Failed to run "npm run start". Start script defined in package.json:

            "scripts": {
                "start":  "node server.js"
                 ...
            
Exited with code: 1

The code works on local and worked on heroku before they eliminated free tier.

CodePudding user response:

Cyclic is built on serverless technology (AWS Lambda) this makes the filesystem read-only. The only writable directory is the /tmp. However, since instances of lambda can be shutdown/recycled at anytime it should not be used for permanent storage.

To write files permanently, either write to the integrated S3 bucket or provide your user a pre-signed URL that they can upload the file to.

For more information on file uploads using serverless infrastructure here are the docs: https://docs.cyclic.sh/serverless/stateless#file-upload

  • Related