當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript storage.AngularFireStorage類代碼示例

本文整理匯總了TypeScript中angularfire2/storage.AngularFireStorage的典型用法代碼示例。如果您正苦於以下問題:TypeScript AngularFireStorage類的具體用法?TypeScript AngularFireStorage怎麽用?TypeScript AngularFireStorage使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了AngularFireStorage類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: describe

describe('AngularFireStorage', () => {
  let app: FirebaseApp;
  let afStorage: AngularFireStorage;

  beforeEach(() => {
    TestBed.configureTestingModule({
      imports: [
        AngularFireModule.initializeApp(COMMON_CONFIG),
        AngularFireStorageModule
      ]
    });
    inject([FirebaseApp, AngularFireStorage], (app_: FirebaseApp, _storage: AngularFireStorage) => {
      app = app_;
      afStorage = _storage;
    })();
  });

  afterEach(done => {
    app.delete().then(done, done.fail);
  });

  it('should exist', () => {
    expect(afStorage instanceof AngularFireStorage).toBe(true);
  });

  it('should have the Firebase storage instance', () => {
    expect(afStorage.storage).toBeDefined();
  });

  it('should have an initialized Firebase app', () => {
    expect(afStorage.storage.app).toBeDefined();
    expect(afStorage.storage.app).toEqual(app);
  });

  describe('upload task', () => {

    it('should upload and delete a file', (done) => {
      const data = { angular: "fire" };
      const blob = new Blob([JSON.stringify(data)], { type : 'application/json' });
      const ref = afStorage.ref('af.json');
      const task = ref.put(blob);
      const sub = task.snapshotChanges()
        .subscribe(
          snap => { expect(snap).toBeDefined() },
          e => { done.fail(); },
          () => {
            ref.delete().subscribe(done, done.fail);
          });
    });

    it('should upload a file and observe the download url', (done) => {
      const data = { angular: "fire" };
      const blob = new Blob([JSON.stringify(data)], { type : 'application/json' });
      const ref = afStorage.ref('af.json');
      const task = ref.put(blob);
      const url$ = task.downloadURL();
      url$.subscribe(
        url => { expect(url).toBeDefined(); },
        e => { done.fail(); },
        () => { ref.delete().subscribe(done, done.fail); }
      );
    });

    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);
    });

  });

  describe('reference', () => {

    it('it should upload, download, and delete', (done) => {
      const data = { angular: "fire" };
      const blob = new Blob([JSON.stringify(data)], { type : 'application/json' });
      const ref = afStorage.ref('af.json');
      const task = ref.put(blob);
      // Wait for the upload
      const sub = forkJoin(task.snapshotChanges())
        // get the url download
        .mergeMap(() => ref.getDownloadURL())
        // assert the URL
        .do(url => expect(url).toBeDefined())
        // Delete the file
        .mergeMap(url => ref.delete())
        // finish the test
        .subscribe(done, done.fail);
    });

    it('should upload, get metadata, and delete', (done) => {
      const data = { angular: "fire" };
      const blob = new Blob([JSON.stringify(data)], { type : 'application/json' });
      const ref = afStorage.ref('af.json');
      const task = ref.put(blob, { customMetadata: { blah: 'blah' } });
//.........這裏部分代碼省略.........
開發者ID:acipher,項目名稱:angularfire2,代碼行數:101,代碼來源:storage.spec.ts

示例2: 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);
 });
開發者ID:acipher,項目名稱:angularfire2,代碼行數:10,代碼來源:storage.spec.ts

示例3: create

 create(file) {
   let fileName = this.guid();
   let storageRef = this.storage.ref('');
   let uploadTask = storageRef.child(`${fileName}`).put(file);
   return uploadTask.then(
     (snapshot) => {
       return snapshot.downloadURL;
     }
   );
 }
開發者ID:meumobi,項目名稱:infomobi,代碼行數:10,代碼來源:upload.service.ts

示例4: getFileURL

 async getFileURL(path: string) {
   return await this.afStorage
     .ref(path)
     .getDownloadURL()
     .toPromise();
 }
開發者ID:Howsky,項目名稱:chatapp,代碼行數:6,代碼來源:firebase.service.ts


注:本文中的angularfire2/storage.AngularFireStorage類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。