Uploaded images to nestjs app not displaying
godipay
FREEOP

7 months ago

Hello Railway
i have a public file in my projects that when image uploads are done saves there. I deployed on railway, am able to upload images but they dont display. All i can see is thump img.
I also can find the public folder in railway db.
what could be the problem ?

$10 Bounty

7 Replies

Railway
BOT

7 months ago

Hey there! We've found the following might help you get unblocked faster:

If you find the answer from one of these, please let us know by solving the thread!


7 months ago

This thread has been marked as public for community involvement, as it does not contain any sensitive or personal information. Any further activity in this thread will be visible to everyone.

Status changed to Open brody 7 months ago


fra
HOBBYTop 10% Contributor

7 months ago

what's the stack? if you are using docker, did you copy the public folder?


fra

what's the stack? if you are using docker, did you copy the public folder?

godipay
FREEOP

7 months ago

nestjs+prisma+mysql
Yes am using docker and i didnt copy the public folder.
How can i add it please ?


fra
HOBBYTop 10% Contributor

7 months ago

can you post your dockerfile?

in nextjs you would do something like:

COPY --from=installer /app/public ./public

but it depends how did you build your image


godipay
FREEOP

7 months ago

the Docker am taking about is that of railway.
i didnt use a third party to manage file upload. i did a custom file upload


fra
HOBBYTop 10% Contributor

7 months ago

how do you upload the images? usually you use services like S3/ R2/ etc...and then you use the url pointing to the image, can you share a screenshot of the network tab for the image that are failing? maybe you need to update the cors for the bucket you are using?


cbhasib
HOBBY

6 months ago

I am not sure about your exact case, but from my understanding, you are uploading an image to your server folder and want to make it publicly accessible.
If that is the case, then yes, it is possible.

I have implemented a similar approach for handling temporary files in some of my servers using NestJS.

Here is how I did it:

  1. I created a temp folder and added a .gitkeep file inside it so that the folder is tracked but remains empty in Git.

  2. In app.module.ts (or main.module.ts), I imported the following:

ServeStaticModule.forRoot({
  rootPath: join(__dirname, '..', 'src/assets/temp-files'),
}),
  1. I used fs (import fs from 'fs') to save and read files.

  2. For public APIs, based on the route/path, you can read the file and return it in the response.

I hope this helps you.


Loading...