本文整理匯總了TypeScript中@angular/fire/storage.AngularFireStorage.ref方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript AngularFireStorage.ref方法的具體用法?TypeScript AngularFireStorage.ref怎麽用?TypeScript AngularFireStorage.ref使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類@angular/fire/storage.AngularFireStorage
的用法示例。
在下文中一共展示了AngularFireStorage.ref方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: onImageChange
onImageChange(event:any) {
const image = event.target.files[0];
const uploader = document.getElementById('uploader') as HTMLInputElement;
const storageRef = this.storage.ref('images/' + Date.now() + image.name);
const task = storageRef.put(image);
task.snapshotChanges().subscribe((snapshot) => {
document.getElementById('buttonFile').style.visibility = 'hidden';
document.getElementById('uploader').style.visibility = 'visible';
const percentage = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;
uploader.value = percentage.toString();
},
(err:any) => {
document.getElementById('buttonFile').style.visibility = 'visible';
document.getElementById('uploader').style.visibility = 'hidden';
uploader.value = '0';
},
() => {
uploader.value = '0';
document.getElementById('buttonFile').style.visibility = 'visible';
document.getElementById('uploader').style.visibility = 'hidden';
this.draftMessage = task.task.snapshot.ref.name.substring(0, 13);
this.draftImage = task.task.snapshot.ref.name.substring(0, 13);
storageRef.getDownloadURL().subscribe(url => {
this.draftImageDownloadURL = url;
this.addMessage();
event.target.value = '';
});
});
}
示例2: uploadImage
async uploadImage(file) {
const filePath = Date.now() + '.jpg';
const ref = this.storage.ref('upload').child(filePath);
const image = await ref.putString(file, 'data_url', {
contentType: 'image/jpg'
});
const url = await this.getImageUrl(image);
return url;
}
示例3: it
it('should resolve the task as a promise', (done) => {
const data = { angular: "promise" };
const blob = new Blob([JSON.stringify(data)], { type : 'application/json' });
const ref = afStorage.ref('af.json');
const task: AngularFireUploadTask = ref.put(blob);
task.then(snap => {
expect(snap).toBeDefined();
done();
}).catch(done.fail);
});
示例4: referenciaCloudStorage
//Referencia del archivo
public referenciaCloudStorage(nombreArchivo: string) {
return this.storage.ref(nombreArchivo);
}
示例5: finalize
finalize(() => this.downloadURL = this.storage.ref(path).getDownloadURL() )