R
Railway•7mo ago
whitetown

could someone help me with volumes?

Hello, could someone help me with volumes? I used this code to upload the file to temp dir (it's working): const tempDir = fs.mkdirSync(path.join(os.tmpdir(), String(new Date().getTime())), { recursive: true }) const result = [] for (const file of files) { const filePath = path.join(tempDir, file.originalname) fs.writeFileSync(filePath, file.buffer) result.push(filePath) } return result now I added a volume. the mount path initially was /files , i.e. const tempDir = '/files' then I have tried to change it to /app/files , i.e. const tempDir = '/app/files' no luck it cannot create a file there
Solution:
mount volume to /app/files and save files to /app/files
Jump to solution
30 Replies
Percy
Percy•7mo ago
Project ID: b799250d-dd7b-47bb-be65-0ae878afd304
whitetown
whitetownOP•7mo ago
b799250d-dd7b-47bb-be65-0ae878afd304
Brody
Brody•7mo ago
quick question, if they are temp files, why would they need to be stored in a volume?
whitetown
whitetownOP•7mo ago
we decided do not process files immediately, since what we are doing takes a time, but add them to a queue. Also, if we keep the orifinal file, it helps us to repeat/restart our operation in case something failed
Brody
Brody•7mo ago
gotcha what is your current volume's mount point
whitetown
whitetownOP•7mo ago
/app/files
Brody
Brody•7mo ago
dockerfile or nixpacks deployment?
whitetown
whitetownOP•7mo ago
nixpacks I guess. I added it via control panel
Brody
Brody•7mo ago
Do you have a Dockerfile in your repo?
whitetown
whitetownOP•7mo ago
NO
Brody
Brody•7mo ago
what is your current path you are saving files into in code
whitetown
whitetownOP•7mo ago
the current path is the temp folder (I cannot make volumes work and restored temp)
Brody
Brody•7mo ago
please inform me of the full file path currently in use by your code that saves the temp files
whitetown
whitetownOP•7mo ago
"/tmp/1716569487905/CV_EN_Cedric_Lionel_Escher_28091981.pdf" "/tmp/1716569599042/Ivan Gerasymchuk CV2.pdf" "/tmp/1716569599042/KARPOLAN's Resume.pdf" they are already deleted
Brody
Brody•7mo ago
but you have mounted the volume to /app/tmp
whitetown
whitetownOP•7mo ago
the path above is fs.mkdirSync(path.join(os.tmpdir(), String(new Date().getTime())), { recursive: true }) when I replace it to /app/files - it did not wotk I can change the path right now and redeploy, just do not know what path shall I use
whitetown
whitetownOP•7mo ago
No description
Brody
Brody•7mo ago
You need to mount the volume to the same path you save the files to you also have now given me 3 different mount points for your volume makeing increasingly hard for me to help you
whitetown
whitetownOP•7mo ago
sorry, I do not understand. I have tried different paths. tell me please what Mount Path shall I define and then what path shall I use to copy files Using the Volume The volume mount point you specify will be available in your service as a directory to which you can read/write. If you mount a volume to /foobar, your application will be able to access it at the absolute path /foobar. ^^^^^^ tried to write to such a folder - did not work Relative Paths Nixpacks, the default buildpack used by Railway, puts your application files in an /app folder at the root of the container. If your application writes to a directory at a relative path, and you need to persist that data on the volume, your mount path should include the app path. For example, if your application writes data to ./data, you should mount the volume to /app/data. ^^^^^^ tried to write to such a folder - did not work either
Brody
Brody•7mo ago
what do you mean by "such a folder"
whitetown
whitetownOP•7mo ago
in the documentation you have two examples: /foobar /app/data I have tried /files /app/files
Solution
Brody
Brody•7mo ago
mount volume to /app/files and save files to /app/files
whitetown
whitetownOP•7mo ago
ok. I am deploying. will try in a few minutes okay, it seems working now. removing all logging and will try one more time...
Brody
Brody•7mo ago
sounds good
whitetown
whitetownOP•7mo ago
I think that my mistake was that I had to create the folder /app/files honestly, I was thinking that railway will do it
Brody
Brody•7mo ago
if you mount a volume to /app/files an /app/files folder will exist within your container
whitetown
whitetownOP•7mo ago
well, it did not.. I even tries to list files/folders in the code and the folder did not exist
const walk = async (dirPath) =>
Promise.all(
await readdir(dirPath, { withFileTypes: true }).then((entries) =>
entries.map((entry) => {
const childPath = join(dirPath, entry.name)
return entry.isDirectory() ? walk(childPath) : childPath
})
)
)

const files = async (req, res, next) => {
try {
const result = await walk('/app/files') // '/app'
res.status(200).json(result)
} catch (error) {
console.log(error)
next(error)

}
}
const walk = async (dirPath) =>
Promise.all(
await readdir(dirPath, { withFileTypes: true }).then((entries) =>
entries.map((entry) => {
const childPath = join(dirPath, entry.name)
return entry.isDirectory() ? walk(childPath) : childPath
})
)
)

const files = async (req, res, next) => {
try {
const result = await walk('/app/files') // '/app'
res.status(200).json(result)
} catch (error) {
console.log(error)
next(error)

}
}
Brody
Brody•7mo ago
I'm sorry but that means you have misconfigured something, if a folder path was not created when mounting a volume that would break everyone's application who use volumes /app/files would of course be empty though
whitetown
whitetownOP•7mo ago
okay. I am not so experienced with raylway as you are 😉 so I will agree with you.
Duchess
Duchess•4mo ago
New reply sent from Help Station thread:
Hey! I have a microservice where I create 3 temporary files for processing that are stored in my project's root directory. Can I use set my projects root directory path as the mount path somehow if I want to use the volumes provided by railway?
You're seeing this because this thread has been automatically linked to the Help Station thread. New reply sent from Help Station thread:
Nope, volumes are empty when created, so that would therefore create an empty project directory, you would need to store the files in a subfolder.But you said they are temp files, I can't see you needing a volume for temp files, volumes are used for persistence.
You're seeing this because this thread has been automatically linked to the Help Station thread. New reply sent from Help Station thread:
During processing, these files are added to a queue and eventually uploaded to file.io, from where users can download them. Although these files are temporary, they need to persist for a short period until the processing and upload are complete.If I create a subfolder in my root directory with the name temp_files, Should my mount path then be set to /temp_files if I use volumes?
You're seeing this because this thread has been automatically linked to the Help Station thread. New reply sent from Help Station thread:
Although these files are temporary, they need to persist for a short period until the processing and upload are complete.The files will persist for as long as that particular deployment is active, I don't see the need for a volume here.> If I create a subfolder in my root directory with the name temp_files, Should my mount path then be set to /temp_files if I use volumes?Nope, volume mount points are full paths and are not relative to the project location within the container, if you are using nixpacks the default project directory would be /app so your mount point would be /app/temp_files
You're seeing this because this thread has been automatically linked to the Help Station thread. New reply sent from Help Station thread:
Okay. Thanks for the help. Appreciate it.
You're seeing this because this thread has been automatically linked to the Help Station thread.
Want results from more Discord servers?
Add your server