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

Multer destination file is not readable by ZEIT server

我收到以下错误:no such as file or directory public/uploads/bae1774e-d6dc-454b-ba63-a4c8c53d3053.png 当我使用 multer hosted through ZEIT

将图像上传到服务器 (nodejs) 时
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

now.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
  }
}

源视图:

这意味着 public 目录已显示

那么知道为什么在托管节点 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