import { Blob } from '@firebase/firestore-types';
@Injectable()
export class ImagehandlerProvider {
nativepath: any;
firestore = firebase.storage();
imagestore: any;
constructor(public filechooser: FileChooser, public blob: Blob) {
console.log('Hello ImagehandlerProvider Provider');
}
uploadimage() {
var promise = new Promise((resolve, reject)=> {
this.filechooser.open().then((url)=> {
(<any>window).FilePath.resolveNativePath(url, (result)=> {
this.nativepath = result;
(<any>window).resolveLocalFileSystemURL(this.nativepath, (res)=> {
res.File((resFile)=> {
var reader = new FileReader();
reader.readAsArrayBuffer(resFile);
reader.onloadend = (ent: any) => {
// var imgBlob = new Blob([ent.target.result], {type: 'image/jpeg'});
var imgBlob = new Blob([ent.target.result], {type: 'image/jpeg'});
var imgStore = this.firestore.ref(firebase.auth().currentUser.uid).child('profilepic');
imgStore.put(imgBlob).then((res)=> {
alert('Upload successful');
}).catch((error)=> {
alert('Upload failed' + error);
})
}
})
})
})
})
})
}
}
上面的代码有一个简单的问题。我在第3天学习离子角度,我想实现图像上传,我认为默认情况下,角度使所有导入的类都是私有的。我已经在网上搜索了如何实现Blob,并且通过实例化我所做的Blob类来判断它是什么,因为默认情况下该类是私有的,它不可访问所以我必须创建一个公共属性。这个类的构造函数。简而言之,在没有创建此属性的情况下,我收到此错误:
[ts] Constructor of class 'Blob' is private and only accessible within the class declaration.
如何使用Blob类