Guest User

Untitled

a guest
Jul 17th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. onSubmitInvoiceData = () => {
  2. const { files } = this.state;
  3. if(files.length < 1) this.setState({ isLoading: false, errors: {...this.state.errors, general: ['Gelieve minstens één factuur te uploaden']} });
  4. else {
  5. const promises = [];
  6. const filesArr = [];
  7.  
  8. files.forEach(file => {
  9. const uploadTask = Storage.ref(`session-123/files/${file.name}`).put(file);
  10. promises.push(uploadTask);
  11.  
  12. uploadTask.on('state_changed', snapshot => {
  13. const progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;
  14. }, error => { console.log(error) }, async () => {
  15. await uploadTask.snapshot.ref.getDownloadURL().then(downloadURL => {
  16. console.log('url: ', downloadURL);
  17. filesArr.push({id: file.id, name: file.name, url: downloadURL});
  18. });
  19. });
  20. });
  21.  
  22. Promise.all(promises).then(tasks => {
  23. console.log('tasks: ', tasks);
  24. Database.ref(`sessions/123`).update({
  25. lastUpdate: Firebase.database.ServerValue.TIMESTAMP,
  26. files: filesArr
  27. }).then(() => this.setState({ isLoading: false }))
  28. });
  29. }
  30. }
Add Comment
Please, Sign In to add comment