如何将文件传递给服务器,然后将其发送回客户端?
我目前正在使用ReactJ中的PDF文件,并在我的服务器端修改它们。问题是,我不知道如何将文件数据传递到服务器端,然后将其发送回。
这就是我获取文件的方式:
<div className={"input-file"}>
<input className="file-upload-field" type="file" accept="application/pdf" onChange={onFileChange}/>
</div>
然后我有
async function modifyPdf(doc, pageNumber) {
let chemin = [
`/testun/${doc}`
];
await Promise.all(chemin.map(url => {
fetch(url)
.then(checkStatus) // check the response of our APIs
.then(parseJSON) // parse it to Json
.catch(error => console.log('There was a problem!', error))
}
))
.then(response => {
newdoc = response[0];
});
return doc//newdoc;
}
问题是,如果我想发送一个URL,那将是本地的,所以节点将无法检索资源(我认为?因为它是blob url),并且是可以通过ArrayBuffer吗?因为当我这样做时,它将[Object ArrayBuffer]作为参数传递给我的路线,因此我真的不知道是否有更好的选择。
谢谢你!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 multer 上传文件。您可以从服务器上的目标文件夹或local
upload.single('productImage')访问输入元素名称,您可以使用 req.file.file.filename
之后,您可以访问前端
http:// localhost:3000/uploads/&lt; filename&gt;
You can upload your files using multer. You can access the uploaded file from the destination folder on the server or local
upload.single('productImage') refers to the the input element name and you can get the file name on the backend with req.file.filename
After that you can access the file on the front-end
http://localhost:3000/uploads/<filename>