|
|
|
@ -5,6 +5,8 @@ import TopBar from '../components/TopBar';
|
|
|
|
|
import { addXlsFile } from '../redux/actions/sessions';
|
|
|
|
|
import { useDispatch } from 'react-redux';
|
|
|
|
|
import * as DocumentPicker from 'expo-document-picker';
|
|
|
|
|
import { uploadFiles, DocumentDirectoryPath } from 'react-native-fs';
|
|
|
|
|
|
|
|
|
|
export default function NewTrack(props: { navigation: any }) {
|
|
|
|
|
const { navigation } = props;
|
|
|
|
|
const dispatch = useDispatch();
|
|
|
|
@ -28,6 +30,15 @@ export default function NewTrack(props: { navigation: any }) {
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// var files = [
|
|
|
|
|
// {
|
|
|
|
|
// name: "file",
|
|
|
|
|
// filename: "file.jpg",
|
|
|
|
|
// filepath: pickedDocument.uri,
|
|
|
|
|
// filetype: "image/jpeg",
|
|
|
|
|
// },
|
|
|
|
|
// ];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// const handleConfirm = async () => {
|
|
|
|
|
// if (!pickedDocument || !trackName || !sessionName) {
|
|
|
|
@ -93,30 +104,34 @@ export default function NewTrack(props: { navigation: any }) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
const file = new File([await pickedDocument.uri], pickedDocument.name, { type: pickedDocument.type });
|
|
|
|
|
const url = 'https://r-dash.azurewebsites.net/File?pseudoPilote=test_PILOTE&nameSession=weeke&nameCircuit=test_CIRCUIT&typeSession=Training';
|
|
|
|
|
//const file = new File([await pickedDocument.uri], pickedDocument.name, { type: pickedDocument.type });
|
|
|
|
|
const url = 'https://r-dash.azurewebsites.net/File?pseudoPilote=test_PILOTE&nameSession=test%20import&nameCircuit=test_CIRCUIT&typeSession=Training';
|
|
|
|
|
const formData = new FormData();
|
|
|
|
|
formData.append('file', file);
|
|
|
|
|
// formData.append('pseudoPilote', 'test_PILOTE');
|
|
|
|
|
// formData.append('nameSession', sessionName);
|
|
|
|
|
// formData.append('nameCircuit', 'test_CIRCUIT');
|
|
|
|
|
// formData.append('typeSession', 'Training');
|
|
|
|
|
console.log(pickedDocument.type);
|
|
|
|
|
console.log(pickedDocument.uri);
|
|
|
|
|
formData.append('file',
|
|
|
|
|
{
|
|
|
|
|
name: pickedDocument.name,
|
|
|
|
|
type: "application/vnd.ms-excel",
|
|
|
|
|
uri : pickedDocument.uri,
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const response = await fetch(url, {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
body: file,
|
|
|
|
|
body: formData,
|
|
|
|
|
headers: {
|
|
|
|
|
Accept: '*/*',
|
|
|
|
|
'accept':'*/*',
|
|
|
|
|
'Content-Type': 'multipart/form-data',
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const data = await response.json();
|
|
|
|
|
console.log('API response:', data);
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
throw new Error('Failed to upload file');
|
|
|
|
|
throw new Error( JSON.stringify(response) + 'Failed to upload file');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const data = await response.json();
|
|
|
|
|
console.log('API response:', data);
|
|
|
|
|
|
|
|
|
|
navigation.goBack();
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.log('Error - POST FILE', error);
|
|
|
|
|