在我的React Native应用程序中,我必须通过POST将PDF文件从本地文件系统发送到后端服务器。它需要采用Uint8Array格式。就目前而言,我可以从本地文件系统中正确地选择一个文件,这给了我它的绝对路径。我应该如何将它与其他内容一起放入JSON主体中?
编辑:我通过解决了这个问题
RNFS.readFile(filePath, 'ascii')
.then((res) => {
const data = res.split("").map(x => x.charCodeAt(0));
let uint8array = new TextEncoder("ascii").encode(data);
也许你可以试试
var string = new TextDecoder("utf-8").decode(uint8array);
并在发送之前在JSON中设置此字符串?