10000 Switch to a Promise for watching upload completion of storage sample. · rasata/quickstart-js@b37b643 · GitHub
[go: up one dir, main page]

Skip to content

Commit b37b643

Browse files
author
Nicolas Garnier
committed
Switch to a Promise for watching upload completion of storage sample.
Change-Id: I71d0afc1a6b4166eb75c7016939c44eacb8ad3bc
1 parent b77e8ec commit b37b643

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

storage/index.html

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -85,22 +85,19 @@ <h6>File URL:</h6>
8585
};
8686

8787
// Push to child path.
88-
var uploadTask = storageRef.child('images/' + file.name).put(file, metadata);
89-
90-
// Listen for errors and completion of the upload.
9188
// [START oncomplete]
92-
uploadTask.on('state_changed', null, function(error) {
93-
// [START onfailure]
94-
console.error('Upload failed:', error);
95-
// [END onfailure]
96-
}, function() {
97-
console.log('Uploaded',uploadTask.snapshot.totalBytes,'bytes.');
98-
console.log(uploadTask.snapshot.metadata);
99-
var url = uploadTask.snapshot.metadata.downloadURLs[0];
89+
storageRef.child('images/' + file.name).put(file, metadata).then(function(snapshot) {
90+
console.log('Uploaded', snapshot.totalBytes, 'bytes.');
91+
console.log(snapshot.metadata);
92+
var url = snapshot.metadata.downloadURLs[0];
10093
console.log('File available at', url);
10194
// [START_EXCLUDE]
10295
document.getElementById('linkbox').innerHTML = '<a href="' + url + '">Click For File</a>';
10396
// [END_EXCLUDE]
97+
}).catch(function(error) {
98+
// [START onfailure]
99+
console.error('Upload failed:', error);
100+
// [END onfailure]
104101
});
105102
// [END oncomplete]
106103
}

0 commit comments

Comments
 (0)
0