DEV Community

Cover image for Setting tmp Folder Using express-fileupload before Deploying to Cyclic.sh
Awosise Oluwaseun
Awosise Oluwaseun

Posted on

Setting tmp Folder Using express-fileupload before Deploying to Cyclic.sh

Error: EROFS: read-only file system, '/var/task/tmp/tmp...'

You are here because you probably just finished a file upload feature that runs well locally but on deploying it to cyclic.sh, you encountered the error above.

Don't fret, there are 2 key things to know about this error:

  1. You can only write to a tmp folder which must be in the root folder of your project directory.
  2. Cyclic.sh tries to navigate the tmp folder relative to the current working directory which is not the root folder of your project. Hence, it appends /var/task/ to the tmp directory itself.

The simple solution is to set the value of one of the parameters in your express-fileupload package as shown below. I would assume you have installed both express-fileupload and express, if not, run the following command:

 npm install express-fileupload express
// The Solution
const express = require('express');
const fileupload = require('express-fileupload');

app.use(fileupload({
    useTempFiles: true,
    tempFileDir: "/tmp",
}))
Enter fullscreen mode Exit fullscreen mode

It is important that you set the value of the tempFileDir property to be \tmp. This way, cyclic.sh is able to navigate the tmp folder relative to the root directory. You can read more on express-fileupload.

I hope this helped. Thanks for reading.

Top comments (4)

Collapse
 
infogenies profile image
InfoGenies

i do the same code but the problem still exist
Image description

Collapse
 
lonewolfgie profile image
LoneWolf-gie

can the photo be obtained?

Collapse
 
jhhornn profile image
Awosise Oluwaseun • Edited

Yes, I was.
I used it alongside cloudinary which saved my data in cloud and I could just fetch from there.
The tmp folder just served as an intermediary folder between my deployed app and where I finally want it(cloudinary)

Collapse
 
lonewolfgie profile image
LoneWolf-gie

I had the same problem. In my problem, I was able to write data to temp folder but still can't get data from that folder?