Пытаюсь отослать файл на сервер
Получаю информацию о файле из галлереи с помощью react-native-image-picker
const file = {
contentType: "image/jpeg"
data: "/9j/4AAQSkZJRgABAQAAAQABAAD/4VGmRXhpZgAASUkqAAgAAA"
fileName: "image-9b223fbf-8401-4668-99b7-80db6da5ac03.jpg"
fileSize: 210829
fullName: "image-9b223fbf-8401-4668-99b7-80db6da5ac03.jpg"
height: 960
isVertical: true
originalRotation: 0
path: "/storage/emulated/0/Pictures/images/image-9b223fbf-8401-4668-99b7-80db6da5ac03.jpg"
tag: "common"
timestamp: "2020-11-11T07:34:04Z"
type: "image/jpeg"
uri: "content://media/external/images/media/34"
url: "content://media/external/images/media/34"
}
async saveFile (file: any, tag: string = 'common') {
const token = await AsyncStorage.getItem('access.token');
var myHeaders = new Headers();
myHeaders.append("Authorization", `Bearer ${token}`);
myHeaders.append("Content-Type", "multipart/form-data");
// myHeaders.append("Content-Type", "application/json; charset=utf-8");
var formdata = new FormData();
formdata.append("tag", tag);
formdata.append("file", file.data);
// formdata.append("file", `data:${file.contentType};base64,${file.data}`);
// formdata.append("file", {
// type: file.type,
// name: file.fileName,
// uri: file.uri
// });
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: formdata,
// redirect: 'follow'
};
fetch("https://hozu-dev.car.tatar:5001/api/file", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
}