| 20 | } |
| 21 | |
| 22 | uploadText() { |
| 23 | if (!this.textToUpload?.trim?.().length) { |
| 24 | return; |
| 25 | } |
| 26 | const metadata = new Metadata(); |
| 27 | metadata.contentType = 'text/plain'; |
| 28 | this.storage |
| 29 | .ref() |
| 30 | .child(`text_files/${this.textToUploadFileName ? this.textToUploadFileName : Date.now()}.txt`) |
| 31 | .putString(this.textToUpload, null, metadata) |
| 32 | .on(TaskEvent.STATE_CHANGED, { |
| 33 | complete() { |
| 34 | console.info('uploadText', 'completed'); |
| 35 | }, |
| 36 | error(err) { |
| 37 | console.error('uploadText', 'error', err); |
| 38 | }, |
| 39 | next(snapshot) { |
| 40 | console.info('uploadText', 'next', 'state', snapshot.state, snapshot.error); |
| 41 | if (snapshot.totalBytes) { |
| 42 | console.log('uploadFile', 'next', 'progress %', snapshot.bytesTransferred / snapshot.totalBytes ?? 0 * 100); |
| 43 | } |
| 44 | if (snapshot.error) { |
| 45 | console.error('uploadText', 'next', snapshot.error); |
| 46 | } |
| 47 | }, |
| 48 | }); |
| 49 | } |
| 50 | |
| 51 | uploadFile() { |
| 52 | const file = File.fromPath( |