Question

Image Saved in Project tmp directory not showing

In my nestjs app deployed on DO app platform, I am uploading images and saving them in a directory tmp/folder/folder

The problem is when I GET the image and pass it into image tag’s src attributes it doesn’t work

<img src="tmp/folder/folder/30eb2c5251413f9ec49457bcab827db3" alt="">
this doesn't display the image

I don’t know what I am doing wrong here


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

KFSys
Site Moderator
Site Moderator badge
November 25, 2022

Hi @msadiq,

If you are writing files for temporary use, you can use the local filesystem. However, keep these two things in mind:

Instances are ephemeral, and are being continuously created and destroyed as the app is scaled, redeployed, etc, and any changes to the filesystem will be destroyed with the instance. This means that every redeployment of your app will reset the filesystem.

If you have a multi-instance app from scaling horizontally, you should remember that each instance has a separate filesystem. Because of this, you should not use the local filesystem for anything that needs to be stateful.

More about that here:

https://docs.digitalocean.com/products/app-platform/how-to/store-data/

In our case, I’ll recommend using Spaces. DigitalOcean offers a product called Spaces, which is compatible with Amazon’s S3 buckets. Spaces provide programmatic access to file storage at scale.

https://docs.digitalocean.com/products/spaces/quickstart/

Bobby Iliev
Site Moderator
Site Moderator badge
November 24, 2022

Hi there,

The App Platform storage is ephemeral, this means that after every new deployment, all of the data saved on there will be wiped out.

In order to store your data persistently, you should use S3 storage like the DigitalOcean Spaces:

https://www.digitalocean.com/community/tutorials/how-to-upload-a-file-to-object-storage-with-node-js

That way your files will be uploaded to the S3 storage rather than the local storage of the App Platform.

Hope that this helps!

Best,

Bobby

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

card icon
Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Sign up
card icon
Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We’d like to help.

Learn more
card icon
Become a contributor

You get paid; we donate to tech nonprofits.

Learn more
Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow – whether you’re running one virtual machine or ten thousand.

Learn more ->
DigitalOcean Cloud Control Panel
Get started for free

Enter your email to get $200 in credit for your first 60 days with DigitalOcean.

New accounts only. By submitting your email you agree to our Privacy Policy.

© 2023 DigitalOcean, LLC.