Я хочу загрузить изображение, но, похоже, получаю ошибку сетевого запроса.
пример значений {"name": "IMG20200427083924.jpg", "type": "image / jpeg", " uri ":" content: //com.google.android.apps.photos.contentprovider/-1/1/content%3A%2F%2Fmedia%2Fexternal%2Fimages%2Fmedia%2F240735/ORIGINAL/NONE/image%2Fjpeg /158476572"casts.
Я правильно делаю?
export const uploadDocumentAction = (profpic) => {
console.log(Endpoint.UPLOAD_DOCUMENT_URL)
return async (dispatch) => {
dispatch(uploadDocument());
try {
let body = new FormData();
body.append('document', { uri: profpic.uri, name: profpic.filename, type: profpic.type });
await AsyncStorage.getItem('accessToken', (error, accessToken) => {
fetch(Endpoint.UPLOAD_DOCUMENT_URL, {
method: 'POST',
headers: {
'Content-Type': 'multipart/form-data',
Authorization: `Bearer ${accessToken}`
},
body: body
})
.then((response) => response.json())
.then((responseJson) => {
console.log(responseJson)
dispatch(uploadDocumentSuccess(responseJson));
})
.catch((error) => {
console.log('error', error);
dispatch(uploadDocumentFailed())
})
});
} catch (error) {
console.log(error);
dispatch(uploadDocumentFailed('Internal Server Error'))
}
}
}