Skip to content

Instantly share code, notes, and snippets.

@meftunca
Created March 17, 2020 16:55
Show Gist options
  • Save meftunca/e5677b459bf64e4a25820177c28247ab to your computer and use it in GitHub Desktop.
Save meftunca/e5677b459bf64e4a25820177c28247ab to your computer and use it in GitHub Desktop.
const uploadFile = files => {
const headers = new Headers();
// headers.append('Accept', 'application/json');
headers.append('Content-Type', 'multipart/form-data');
headers.append(
'Authorization',
'XPHBO4yPFDeXv-1FfqBIiOGwtvkSFH71Nmi-Hye0QQQ=',
);
let uploadFunctions = async file => {
let {uri, type: mimeType, fileName} = file;
uri = Platform.OS === 'android' ? uri : uri.replace('file://', '');
const formData = new FormData();
formData.append(
'json',
JSON.stringify({
sharingMode: 'public',
}),
);
// console.log('file', file);
formData.append('document', {
uri: file.uri,
type: 'image/jpeg', //file.type,
name: file.name,
});
// try {
// const response = await fetch(
// 'https://stg-documents-api.workmaple.com/v1/documents', //https://documents-api.workmaple.com/v1/documents
// config,
// );
// console.log('response', response);
// const data = await response.json();
// console.log('data', data);
// return data;
// } catch (error) {
// console.log('error', error);
// }
axios
.post(
`https://stg-documents-api.workmaple.com/v1/documents`,
formData,
{
headers: {
Accept: 'application/json',
'Content-Type': 'multipart/form-data',
Authorization: `XPHBO4yPFDeXv-1FfqBIiOGwtvkSFH71Nmi-Hye0QQQ=`,
},
// onUploadProgress: ,
},
)
.catch(error => {
throw error;
});
};
return Promise.all(files.map(uploadFunctions));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment