Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- onSubmitInvoiceData = () => {
- const { files } = this.state;
- if(files.length < 1) this.setState({ isLoading: false, errors: {...this.state.errors, general: ['Gelieve minstens één factuur te uploaden']} });
- else {
- const promises = [];
- const filesArr = [];
- files.forEach(file => {
- const uploadTask = Storage.ref(`session-123/files/${file.name}`).put(file);
- promises.push(uploadTask);
- uploadTask.on('state_changed', snapshot => {
- const progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;
- }, error => { console.log(error) }, async () => {
- await uploadTask.snapshot.ref.getDownloadURL().then(downloadURL => {
- console.log('url: ', downloadURL);
- filesArr.push({id: file.id, name: file.name, url: downloadURL});
- });
- });
- });
- Promise.all(promises).then(tasks => {
- console.log('tasks: ', tasks);
- Database.ref(`sessions/123`).update({
- lastUpdate: Firebase.database.ServerValue.TIMESTAMP,
- files: filesArr
- }).then(() => this.setState({ isLoading: false }))
- });
- }
- }
Add Comment
Please, Sign In to add comment