2020-12-01 20:19:48 +00:00
|
|
|
import RNFetchBlob from 'rn-fetch-blob';
|
|
|
|
|
2022-03-16 19:07:49 +00:00
|
|
|
import { TMethods } from '../fetch';
|
2022-01-12 12:54:04 +00:00
|
|
|
import { IFileUpload } from './interfaces';
|
|
|
|
|
2020-12-01 20:19:48 +00:00
|
|
|
class FileUpload {
|
2022-01-12 12:54:04 +00:00
|
|
|
fetch = (method: TMethods, url: string, headers: { [key: string]: string }, data: IFileUpload[]) => {
|
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;
|