gpt4 book ai didi

javascript - ZEIT 服务器无法读取 Multer 目标文件

转载 作者:行者123 更新时间:2023-11-29 20:37:26 25 4
gpt4 key购买 nike

我收到以下错误:no such as file or directory public/uploads/bae1774e-d6dc-454b-ba63-a4c8c53d3053.png 当我将图像上传到服务器 (nodejs) 时使用 multer通过 ZEIT 托管

const multerMultiple = {
storage: multer.diskStorage({
destination: (req, file, callback) => {
callback(null, "./public/uploads"); // I think the problem here
},
filename: (req, file, callback) => {
const extension = file.mimetype.split("/")[1];
const name = `${uuid.v4()}.${extension}`;
callback(null, name);
}
})
};

The configuration above is working perfectly locally, while the node js is running locally

现在.json

{
"name": "application-name",
"version": 2,
"builds": [
{ "src": "index.js", "use": "@now/node-server" },
{ "src": "./public/uploads", "use": "@now/static" }
],
"routes": [{ "src": "/.*", "dest": "/index.js" }],
"env": {
.../ env here
}
}

源 View :

enter image description here

这意味着公共(public)目录被呈现

那么知道为什么在托管 Node js 时我会遇到出现的问题吗? ZEIT now 配置中是否缺少某些内容或与我的代码相关的内容?

最佳答案

看起来您正在尝试将文件上传到您的应用程序,在 Zeit 上作为 lambda 运行。

Zeit 在 AWS Lambda 之上运行。 AWS Lambda,以及 Now lambda,在执行期间仅提供非常有限的文件系统写入,但在执行完成时任何更改都将丢失。 lambda 执行之间没有持久性。

相反,您需要将文件写入某种持久存储,例如 AWS S3。这是您如何执行此操作的示例:https://github.com/zishon89us/node-cheat/tree/master/aws/express_multer_s3

关于javascript - ZEIT 服务器无法读取 Multer 目标文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56429409/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com