2020-12-01 20:19:48 +00:00
|
|
|
import RNFetchBlob from 'rn-fetch-blob';
|
|
|
|
|
|
|
|
class FileUpload {
|
|
|
|
fetch = (method, url, headers, data) => {
|
2021-09-13 20:41:05 +00:00
|
|
|
const formData = data.map(item => {
|
2020-12-01 20:19:48 +00:00
|
|
|
if (item.uri) {
|
|
|
|
return {
|
|
|
|
name: item.name,
|
|
|
|
type: item.type,
|
|
|
|
filename: item.filename,
|
|
|
|
data: RNFetchBlob.wrap(decodeURI(item.uri))
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return item;
|
|
|
|
});
|
|
|
|
|
|
|
|
return RNFetchBlob.fetch(method, url, headers, formData);
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-12-01 20:19:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const fileUpload = new FileUpload();
|
|
|
|
export default fileUpload;
|