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
30 Replies
Project ID:
b799250d-dd7b-47bb-be65-0ae878afd304
b799250d-dd7b-47bb-be65-0ae878afd304
quick question, if they are temp files, why would they need to be stored in a volume?
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
gotcha
what is your current volume's mount point
/app/files
dockerfile or nixpacks deployment?
nixpacks I guess. I added it via control panel
Do you have a Dockerfile in your repo?
NO
what is your current path you are saving files into in code
the current path is the temp folder (I cannot make volumes work and restored temp)
please inform me of the full file path currently in use by your code that saves the temp files
"/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
but you have mounted the volume to
/app/tmp
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
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
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
what do you mean by "such a folder"
in the documentation you have two examples:
/foobar
/app/data
I have tried
/files
/app/files
Solution
mount volume to
/app/files
and save files to /app/files
ok. I am deploying. will try in a few minutes
okay, it seems working now. removing all logging and will try one more time...
sounds good
I think that my mistake was that I had to create the folder /app/files
honestly, I was thinking that railway will do it
if you mount a volume to
/app/files
an /app/files
folder will exist within your containerwell, it did not..
I even tries to list files/folders in the code and the folder did not exist
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 thoughokay. I am not so experienced with raylway as you are 😉 so I will agree with you.
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_filesYou'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.