Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image not showing immediately after uploading in sails.js

Tags:

sails.js

In my application ,I have stored uploaded images to folder ./assets/uploads. I am using easyimage and imagemagick for storing the images.

In my application, after uploading the images, it should show the new uploaded image. But it is not displayed even if the page is refreshed. But when i do sails lift , the image is shown.

How to show image immediately after uploading the image? Thanks a lot!

like image 379
Mahahari Avatar asked Mar 17 '14 09:03

Mahahari


1 Answers

It's a totally normal situation, because of the way Sails works with the assets.

The thing is that upon sails lift the assets are being copied (including directory structure and symlinks) from ./assets folder to ./.tmp/public, which becomes publicly accessible.

So, in order to show your images immediately after upload, you, basically, need to upload them not to ./assets/uploads but to ./.tmp/public/uploads.

The only problem now is that the ./.tmp folder is being rewritten each time your application restarts, and storing uploads in ./tmp/... would make them erased after every sails lift. The solution here would be storing uploads in, for example, ./uploads and having a symlink ./assets/uploads pointing to ../uploads.

like image 62
bredikhin Avatar answered Oct 20 '22 03:10

bredikhin