当应用在生产环境中运行时,在Sails.js中上传后,图像无法立即加载

问题描述 投票:2回答:0

我已经将图像上传并存储在/ assets / images / path / to / image中。 在开发环境中一切都很好。 但是,当我在生产环境中运行我的应用程序时,首先遇到的问题是,上传后图像不会立即显示。 但是可以通过帆重启服务器后查看图像。

我搜索解决方案,然后想到了将相同的上载文件复制到/.tmp文件夹中的想法,以立即访问上载的图像。 所以我尝试此解决方案并使用以下代码将图像复制到.tmp文件夹中...

var tempLocation = process.cwd()+ '/.tmp/public/images/custom/path/to/image';
fs.createReadStream(uploadLocation).pipe(fs.createWriteStream(tempLocation));

但是后来我写.tmp时出现错误

    events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: ENOENT, open path/to/.tmp/folder;

我已经在全球和本地安装了grunt。 所以不要以为这是个问题。 请帮我解决这个问题。 谢谢

node.js image file-upload sails.js image-uploading
© www.soinside.com 2019 - 2024. All rights reserved.