好的,我使用expo来管理我的react原生应用程序,在我的一个功能中,我允许用户选择要上传的文件,问题是用户可以选择任何类型的文件,因此我使用documentpicker,用户可以选择他想要上传的文件,问题是由于一些服务器容量问题,我需要使用imagemanipulator来操作图像,这样它就可以更好地适应可用空间,但是每当我向imagemanipulator提供文件uri时,我就会得到一个错误“[未处理的承诺拒绝:错误:hostfunction中的异常:来自js的错误调用:字段大小不同。]”。这是我的密码:
let result = await DocumentPicker.getDocumentAsync({
type:"*/*" ,
});
if (!result.cancelled) {
const fileType=result.uri.substr(result.uri.lastIndexOf('.') + 1);
if(fileType==="jpg" || fileType==="png" || fileType==="gif"){
const manipResult = await ImageManipulator.manipulateAsync(
result.uri,
[{ resize: { width: manipulatedWidth, height: manipulatedHeight } }],
{ compress: 0.7, format: ImageManipulator.SaveFormat.JPEG }
);
}
}
无论何时我使用imagepicker而不是documentpicker,我都不会得到这个错误,但是在这种情况下,我真的需要使用documentpicker,这样用户就可以选择上传哪个文件。
暂无答案!
目前还没有任何答案,快来回答吧!