Gow*_*man 1 document react-native react-native-web
我正在使用react-native-document-picker表单,使用以下代码从Android手机中选择文件
DocumentPicker.show({
filetype: [DocumentPickerUtil.images()],
},(error,res) => {
// Android
console.log(
res.uri,
res.type, // mime type
res.fileName,
res.fileSize
);
});
Run Code Online (Sandbox Code Playgroud)
上面日志的输出就像
uri: 'content://com.android.providers.media.documents/document/image%3A48',
type: 'image/jpeg'
fileName: 'TestImage.jpeg'
fileSize: 5301
Run Code Online (Sandbox Code Playgroud)
如何在 React Native 中获取上传文件的字节数组并将其作为 Web api post 请求的输入发送。
这对我有用
DocumentPicker.show({
filetype: [DocumentPickerUtil.images()],
},(error,res) => {
const data = new FormData();
data.append('name', 'testName'); // you can append anyone.
data.append('photo', {
uri: res.uri,
type: res.type,
name: res.fileName,
});
fetch('http://ApiUrl/api/Controller/UploadFile', {
method: 'post',
headers: {
'Content-Type': 'multipart/form-data',
},
body: data
}).then(res => {
console.log(res)
})
.catch(function(error) {
console.log('There has been a problem with your fetch operation: ' + error.message);
throw error;
});
});Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8712 次 |
| 最近记录: |