我将尝试使用React、Next.js和Ant Design构建文件上传。在本地测试时,一切都正常。但是当我部署到实例上并尝试上传文件时,出现以下错误:
我使用的用户界面(UI)如下所示:
Request URL: https://my-app.my-team.now.sh/url/for/test/
Request Method: POST
Status Code: 405
Remote Address: 34.65.228.161:443
Referrer Policy: no-referrer-when-downgrade
我使用的用户界面(UI)如下所示:
<Dragger {...fileUploadProps}>{renderImageUploadText()}</Dragger>
其中fileUploadProps
是:
const fileUploadProps = {
name: 'file',
multiple: false,
showUploadList: false,
accept: 'image/png,image/gif,image/jpeg',
onChange(info) {
const { status } = info.file;
if (status === 'done') {
if (info.file.size > 2000000) {
setUploadSizeError('File size is too large');
} else {
handleFieldValue(API_FORM_FIELDS.PICTURE, info);
}
} else if (status === 'error') {
setUploadSizeError(`${info.file.name} file upload failed.`);
}
},
};
我猜这可能与Next.js的服务器端渲染有关?另一方面,也可能不是,因为当我导航到url/for/test
时,它应该在客户端上呈现。
你如何使用Ant Design和Next.js实现文件上传?