如何在 next.js API 路由中获取上传的图像并将其保存在公共文件夹中?我已经准备好了前端。我正在使用纯 JavaScript 将图像上传到端点。这里是上传图片的onSubmit函数。如果我在这里做错了,请建议我。主要问题是如何检索它?
const onSubmit=async(e)=>{
e.preventDefault();
const fd=new FormData()
fd.append('myfile',image.name)
let res=await fetch(`http://localhost:3000/api/upload`,{
method: 'POST',
headers: {
"Content-Type": "image/jpeg",
},
body: fd,
})
let response=await res.json();
Run Code Online (Sandbox Code Playgroud)
还有一个额外的问题,将上传的图像保存在公共文件夹中肯定不是一个好主意。我已将其保存在云中的某个位置。