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, railway11 Replies
Project ID:
a85b4083-30a6-432a-b467-33c809a8c6f7
console log the
rootImagePath
variable and tell me what it isProject 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?please fulfill my request
Sorry, here is the console log.
const rootImagePath = ``${process.cwd()}/src/uploads/images``;
console.log("rootImagePath: ", rootImagePath, "\n");
rootImagePath: /app/src/uploads/imagesside note, console log does automatically append a newline
Solution
mount a volume to
/app/src/uploads
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.
sounds good, let me know if that works for you
Thank you very much!
I think it's working now, on each deploy it doesn't delete the images anymore.
great!