Skip to content

Commit 721e850

Browse files
committed
chore(storage): update demo
1 parent 68917b3 commit 721e850

File tree

4 files changed

+39
-8
lines changed

4 files changed

+39
-8
lines changed

apps/demo/src/plugin-demos/firebase-storage.ts

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Observable, EventData, Page } from '@nativescript/core';
1+
import { Observable, EventData, Page, File, knownFolders, path } from '@nativescript/core';
22
import { DemoSharedFirebaseStorage } from '@demo/shared';
33
import { Metadata, Storage, TaskEvent } from '@nativescript/firebase-storage';
44
import { Auth } from '@nativescript/firebase-auth';
@@ -38,11 +38,42 @@ export class DemoModel extends DemoSharedFirebaseStorage {
3838
},
3939
next(snapshot) {
4040
console.info('uploadText', 'next', 'state', snapshot.state, snapshot.error);
41-
console.log('uploadText', 'next', 'progress %', snapshot.bytesTransferred / snapshot.totalBytes ?? 0 * 100);
41+
if (snapshot.totalBytes) {
42+
console.log('uploadFile', 'next', 'progress %', snapshot.bytesTransferred / snapshot.totalBytes ?? 0 * 100);
43+
}
4244
if (snapshot.error) {
4345
console.error('uploadText', 'next', snapshot.error);
4446
}
4547
},
4648
});
4749
}
50+
51+
uploadFile() {
52+
const file = File.fromPath(
53+
path.join(knownFolders.currentApp().path, 'images', 'deadpool.jpeg')
54+
)
55+
const metadata = new Metadata();
56+
metadata.contentType = 'image/jpg';
57+
this.storage
58+
.ref()
59+
.child('images/deadpool.jpeg')
60+
.putFile(file.path, metadata)
61+
.on(TaskEvent.STATE_CHANGED, {
62+
complete() {
63+
console.info('uploadFile', 'completed');
64+
},
65+
error(err) {
66+
console.error('uploadFile', 'error', err);
67+
},
68+
next(snapshot) {
69+
console.info('uploadFile', 'next', 'state', snapshot.state);
70+
if (snapshot.totalBytes) {
71+
console.log('uploadFile', 'next', 'progress %', snapshot.bytesTransferred / snapshot.totalBytes ?? 0 * 100);
72+
}
73+
if (snapshot.error) {
74+
console.error('uploadFile', 'next', snapshot.error);
75+
}
76+
},
77+
});
78+
}
4879
}

apps/demo/src/plugin-demos/firebase-storage.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<TextField text="{{ textToUpload }}" hint="Enter Text to upload"/>
1010
<TextField text="{{ textToUploadFileName }}" hint="Enter Text to upload file name"/>
1111
<Button text="Upload text" tap="{{ uploadText }}" class="btn btn-primary"/>
12+
<Button text="Upload file" tap="{{ uploadFile }}" class="btn btn-primary"/>
1213
<Button text="Test firebase-storage" tap="{{ testIt }}" class="btn btn-primary"/>
1314
</StackLayout>
1415
</ScrollView>

apps/demo/webpack.config.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@ module.exports = (env) => {
1111
config.resolve.alias.set('@demo/shared', resolve(__dirname, '..', '..', 'tools', 'demo'));
1212
});
1313

14-
// Example if you need to share images across demo apps:
15-
// webpack.Utils.addCopyRule({
16-
// from: '../../../tools/images',
17-
// to: 'images',
18-
// context: webpack.Utils.project.getProjectFilePath('node_modules')
19-
// });
14+
webpack.Utils.addCopyRule({
15+
from: '../../../tools/images',
16+
to: 'images',
17+
context: webpack.Utils.project.getProjectFilePath('node_modules')
18+
});
2019

2120
return webpack.resolveConfig();
2221
};

tools/images/deadpool.jpeg

680 KB
Loading

0 commit comments

Comments
 (0)