Dynamic Images
Answered
Erenay posted this in #help-forum
ErenayOP
The images in the new public folder won't load until I build the site the next time. How can I use these images dynamically?
Answered by joulev
the public folder is read-only, you cannot save images there. you must save images elsewhere – for example, in a s3 bucket
13 Replies
@Erenay The images in the new public folder won't load until I build the site the next time. How can I use these images dynamically?
you can load images dynamically by just referencing to it:
Like that the image will be automatically loaded and you can dynamically change the source if needed
<img src='/your/file.png' />
Like that the image will be automatically loaded and you can dynamically change the source if needed
@B33fb0n3 you can load images dynamically by just referencing to it:
tsx
<img src='/your/file.png' />
Like that the image will be automatically loaded and you can dynamically change the source if needed
ErenayOP
So I will use
<img>
instead of <Image>
. Do I understand correctly?@Erenay So I will use `<img>` instead of `<Image>`. Do I understand correctly?
this was just to clarify, what's important. It could also look like this:
<Image src='/your/file.png' />
@B33fb0n3 this was just to clarify, what's important. It could also look like this:
tsx
<Image src='/your/file.png' />
ErenayOP
It's like this now:
Next.js version:
<Image
alt={productData.name}
width={192}
height={192}
className="w-full h-full object-cover"
src={productData.banner}
priority
unoptimized
/>
Next.js version:
14.2.22
After I build and run the site, I put the file correctly in the public folder and the image does not appear until the next build. But it appears when I rebuild the site.
@Erenay The images in the new public folder won't load until I build the site the next time. How can I use these images dynamically?
the public folder is read-only, you cannot save images there. you must save images elsewhere – for example, in a s3 bucket
Answer
any changes to the public folder are only reflected in the next build
ErenayOP
thank you very much
@joulev the public folder is read-only, you cannot save images there. you must save images elsewhere – for example, in a s3 bucket
ErenayOP
So, for example, can I store the images in a different folder in my server other than the public directory?
Is it dynamic that way?
@Erenay So, for example, can I store the images in a different folder in my server other than the public directory?
yea... you can save it anywhere. you can even save it inside
public
as well if you want – but for them to be accessible, you need to create some sort of route handler using fs
to read the file system and return the file as a responsethe only restriction is that if you save it in
public
, it won't be available automatically the way existing files in public
are