I want to send multipart data to the server with XMLHttpRequest
using React Native
.
My code is as follows:
let body = new FormData();
const photo = {
uri: picture.picture.path, //"https://autralis.blob.core.windows.net/devthumbnails/1024x768/79/55/99/79559918324723216216211601856493692575062394716602088366146664699383830311185.jpg"
type: 'image/jpeg',
name: uuid + '.jpg', //66f8580e-4d99-46cb-b8db-e5f13640367c.jpg
};
body.append('photoGUID', uuid); //66f8580e-4d99-46cb-b8db-e5f13640367c
body.append('item', picture.item); //front-left
body.append('photo', photo);
let xhr = new XMLHttpRequest();
xhr.open('POST', Common.mainUrl +'/manager/api/v1/sync/request/picture/');
xhr.onload = function (e) {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
console.log("Success");
}
}
};
xhr.onerror = function (e) {
console.log(JSON.stringify(e));
};
xhr.send(body);
On IOS it works fine, as expected.
But on Android it doesn't work.
If I send only photo
; thus without item
and photoGUID
it works fine, but if I want to send photo and the data than it won't work.
It comes in xhr.onerror
and the error message is as follows:
...
_response": "Could not retrieve file for uri https://autralis.blob.core.windows.net/devthumbnails/1024x768/79/55/99/79559918324723216216211601856493692575062394716602088366146664699383830311185.jpg"
...
Any idea?