Issue with Saving Product Images to Railway Volume

Issue with Saving Product Images to Railway Volume Hello everyone! I'm having trouble trying to save product images to a Railway volume. The situation is as follows: when I save the data in the path /src/uploads, I don't see any changes in the volume metrics. Additionally, every time the server reloads during a deployment, the data gets deleted. What steps should I take to resolve this? In Railway, my volume connection is configured as follows: Mount Path: /src/uploads/ To save the images, I'm using the following code: const rootImagePath = ${process.cwd()}/src/uploads/images; // Check if the folder exists, and if not, create it await access(directoryPath, constants.R_OK) .then(() => console.log("Directory exists")) .catch(async (error) => { console.log("Requested directory does not exist: ", error.message); // Create the directory recursively if it doesn't exist await mkdir(directoryPath, { recursive:true }); }); const filePath = path.join(directoryPath, imageFile.name); // Save the file to the directory await writeFile(filePath, buffer); nextjs, railway
Solution:
mount a volume to /app/src/uploads
Jump to solution
11 Replies
Percy
Percy10mo ago
Project ID: a85b4083-30a6-432a-b467-33c809a8c6f7
Brody
Brody10mo ago
console log the rootImagePath variable and tell me what it is
agusvalori
agusvaloriOP10mo ago
Project ID:a85b4083-30a6-432a-b467-33c809a8c6f7 I MISSED THE FOLLOWING FROM THE CODE: const directoryPath = `${rootImagePath}/products/${articuloID}; HOW CAN I PASS THE COMPLETE CODE?
Brody
Brody10mo ago
please fulfill my request
agusvalori
agusvaloriOP10mo ago
Sorry, here is the console log. const rootImagePath = ``${process.cwd()}/src/uploads/images``; console.log("rootImagePath: ", rootImagePath, "\n"); rootImagePath: /app/src/uploads/images
Brody
Brody10mo ago
side note, console log does automatically append a newline
Solution
Brody
Brody10mo ago
mount a volume to /app/src/uploads
agusvalori
agusvaloriOP10mo ago
Perfect, thank you very much. Now I'll try and see what comes up. Yes, I added the line break because I have several console logs. Because since I didn't know where the files were being saved, I used them to explore the volume folder with the other console logs.
Brody
Brody10mo ago
sounds good, let me know if that works for you
agusvalori
agusvaloriOP10mo ago
Thank you very much! I think it's working now, on each deploy it doesn't delete the images anymore.
Brody
Brody10mo ago
great!
Want results from more Discord servers?
Add your server