我想使用 XMLHttpRequest 发送一个多部分表单。我要附加的文件是一个jpg文件。将文件附加到 FormData 对象可以正常工作。
但我想在发送图像文件之前对其进行处理。因此,我有一个将 Uint8Array 作为输入和输出的库。所以我将处理后的图像作为 UInt8Array。
我试过
form.append("picture", new Blob(fileAsArray, {type: "image/jpg"} ));
但它创建了一个八位位组/流。 那么我如何通过 XMLHttpRequest multipart/form 发送 Uint8Array 以便服务器看到与发送文件对象时相同的内容?
最佳答案
请注意 Blob
constructor将类型化数组(或其他来源)的数组 作为其参数。尝试
form.append("picture", new Blob([fileAsArray], {type: "image/jpg"} ));
关于Javascript:使用 XMLHttpRequest 发送 arrayBuffer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28787203/