Method toFile not overwriting
See original GitHub issueSo, I am downloading an image to the server and then using Sharp to resize it. So in the end I expect the following:
image.png imageResized.png
Both should be the same image but different width and height.
Problem is, the first time I run the program, it works as expected, if I run it again without restarting the server, the “image.png” changes but “imageResized.png” remains the same. It’s as if it couldn’t overwrite it. I’ve also tried to give the “imageResized.png” file different names for each time its generated, like this:
image.png (original image, which is generated each time the program is run) imageResized.png (resized image, generated during the first execution) imageResized2.png (second execution) imageResized3.png (third execution)
In this case, “imageResized.png”, “imageResized2.png” and “imageResized3.png” are the same when they should be each one a unique image.
I think this is related to maybe some cached data since I am getting no errors from the code. I’ve tried to put the “sharp.cache({ files: 0 });” at the start of the file, but it didn’t work. The code I am using to resize the images is:
sharp('/src/assets/bar.png').resize(600).toFile('/src/assets/bar2.png');
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (2 by maintainers)
Top GitHub Comments
Thanks both, if the input filename remains the same but its contents change then adding
sharp.cache(false);
to your respective examples should deal with this.In addition, if
chokidar
is used then ensure itsawaitWriteFinish
setting istrue
.Worked, thank you very much!