在vercel上的Next js中上传服务器错误的文件

Upload file on server error in Next js on vercel

我想上传图片到服务器。

我的代码在本地主机上运行良好,当我想在 vercel 上使用它时发生错误。

2021-09-20T15:33:39.427Z    58fb3aa3-54bb-464e-8a68-fb876ded6cdc    ERROR   Error: EROFS: read-only file system, mkdir '/var/task/public'
    at Object.mkdirSync (fs.js:1009:3)
    at sync (/var/task/node_modules/mkdirp/index.js:72:13)
    at Function.sync (/var/task/node_modules/mkdirp/index.js:78:24)
    at new DiskStorage (/var/task/node_modules/multer/storage/disk.js:21:12)
    at Function.module.exports [as diskStorage] (/var/task/node_modules/multer/storage/disk.js:65:10)
    at Object.2439 (/var/task/.next/server/pages/api/uploads.js:32:38)
    at __webpack_require__ (/var/task/.next/server/webpack-runtime.js:25:42)
    at __webpack_exec__ (/var/task/.next/server/pages/api/uploads.js:102:52)
    at /var/task/.next/server/pages/api/uploads.js:103:28
    at Object.<anonymous> (/var/task/.next/server/pages/api/uploads.js:106:3) {
  errno: -30,
  syscall: 'mkdir',
  code: 'EROFS',
  path: '/var/task/public'
}
RequestId: 58fb3aa3-54bb-464e-8a68-fb876ded6cdc Error: Runtime exited with error: exit status 1
Runtime.ExitError

Local 与 Vercel 不同,Vercel serverless functions 不支持从浏览器上传文件。

File Storage & Uploads