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


TypeScript file.File類代碼示例

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


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

示例1: uploadPhoto

  async uploadPhoto(imageFileUri: any): Promise<void> {
    this.myPhoto = imageFileUri;

    this.error = null;
    this.loading = this.loadingCtrl.create({
      content: 'Uploading...'
    });

    await this.loading.present();

    const fileTransfer: FileTransferObject = this.transfer.create();

    const fileEntry = await this.file.resolveLocalFilesystemUrl(imageFileUri);

    const options: FileUploadOptions = {
      fileKey: 'file',
      fileName: fileEntry.name,
      headers: {}
    };

    try {
      const result = await fileTransfer.upload(imageFileUri, 'http://192.168.178.84:8080/upload', options);
      console.log(result.bytesSent);
      console.log(result.responseCode);
      this.showToast(true);
    }
    catch (e) {
      console.log(e);
      this.showToast(false);
    }
    finally {
      this.loading.dismiss();
    }
  }
開發者ID:ralscha,項目名稱:attic,代碼行數:34,代碼來源:home.ts

示例2:

const existsFile = (path, filename) =>
	FILE.checkFile(path, filename).catch((e) => {
		if (e.code === 1) {
			return false
		}
		return Bluebird.reject(e)
	})
開發者ID:whispeer,項目名稱:app,代碼行數:7,代碼來源:blobCache.ts

示例3: resolve

 return new Promise<void>((resolve, reject) => {
   this.file.removeFile(this.dir.nativeURL, k).then( () => {
     this.log.debug('File removed: ' + k);
     resolve();
   }).catch( (e) => {
     this.log.error(e);
     reject(e);
   });
 });
開發者ID:bitjson,項目名稱:copay,代碼行數:9,代碼來源:file-storage.ts

示例4: getCacheDirectory

		return Bluebird.try(async () => {
			const cacheDir = await getCacheDirectory()
			const blobFile = idToFileName(blobID)
			const path = isAndroid() ? `${FILE.externalRootDirectory}Download/` : `${FILE.documentsDirectory}`
			const existsSource = await existsFile(cacheDir, blobFile)
			const existsDestination = await existsFile(path, filename)

			if (!existsSource) {
				throw new Error(`cannot copy blob, blob does not exist: ${filename}`)
			}

			if (existsDestination) {
				await FILE.removeFile(path, filename)
			}

			await FILE.copyFile(cacheDir, blobFile, path, filename)

			return `${path}${filename}`
		})
開發者ID:whispeer,項目名稱:app,代碼行數:19,代碼來源:blobCache.ts

示例5: copyFile

  // http://ngcordova.com/docs/plugins/file/
  public copyFile(fullFilePath:string, destinationDirectory: string, newFileName? :string) : void {
    let fileName: string = fullFilePath.split('/').pop();
    let cachedImagePath: string = fullFilePath.substring(0, fullFilePath.lastIndexOf('/') + 1);
    let newName: string = newFileName ? newFileName: fileName;

    this.file.copyFile(cachedImagePath, fileName, destinationDirectory, newName).then((result: any) => {
      console.log('File: ' + fileName + ' copied to path: ' + destinationDirectory);
    }).catch(error => {
      console.log('Error when copy file: ' + fileName + ' to path: ' + destinationDirectory + ' - ' + error.message);
    });
  }
開發者ID:exodinn,項目名稱:StarterKit,代碼行數:12,代碼來源:file-service.ts

示例6: writeFileFromBase64

 // here is the method is used to write a file in storage
 // https://www.c-sharpcorner.com/article/how-to-save-picture-to-specific-path-in-ionic-3-using-native-camera-plugin/
 public writeFileFromBase64(base64Data: any, filePath: string, fileName?: string): void {
   let contentType: any = this.getContentType(base64Data);
   let dataBlob: Blob = this.base64toBlob(base64Data.split(',')[1], contentType);
   // TODO dummy random name implementation
   let newFileName: string = fileName ? fileName : Math.floor(Math.random()*Number.MAX_SAFE_INTEGER)+'.jpeg';
   this.file.writeFile(filePath, newFileName, dataBlob, contentType).then((success) => {
     console.log('File Writed Successfully to location: ' + filePath + newFileName);
   }).catch((err) => {
     console.log('Error Occured While Writing File: '+ filePath + newFileName, err.message);
   })
 }
開發者ID:exodinn,項目名稱:StarterKit,代碼行數:13,代碼來源:file-service.ts

示例7: Error

		}).catch(error => {
			return FILE.createDir(basePath, BLOB_CACHE_DIR, true).then(dirEntry => {
				return desiredPath
			}).catch(error => {
				throw new Error('Could not create blob cache directory.')
			})
		})
開發者ID:whispeer,項目名稱:app,代碼行數:7,代碼來源:blobCache.ts

示例8: Observable

 return new Observable(observer => {
   this.file.resolveDirectoryUrl(this.file.dataDirectory).then((directory: DirectoryEntry) => {
     this.file.getDirectory(directory, dirPath, {})
       .then((dir: DirectoryEntry) => observer.next(dir))
       .catch((error) => observer.error(error));
   });
 });
開發者ID:CIRDLES,項目名稱:CHRONI,代碼行數:7,代碼來源:FileUtility.ts

示例9: abrir

 abrir(directorio){
   console.log(directorio.fullPath)
   this.file.listDir(this.file.externalRootDirectory, directorio.fullPath.substring(1, directorio.fullPath.length)).then(
     (list) => {
       console.log(list);
       this.directorios = list;
     }
   ).catch(e => console.log(e));
 }
開發者ID:dguerrerom01,項目名稱:exploradorArchivos,代碼行數:9,代碼來源:home.ts

示例10: retroceder

  retroceder(){
    console.log(this.file.externalRootDirectory)
    this.file.listDir(this.file.externalRootDirectory, '').then(
      (list) => {
        console.log(list);
        this.directorios = list;
      }
    ).catch(e => console.log(e));

  }
開發者ID:dguerrerom01,項目名稱:exploradorArchivos,代碼行數:10,代碼來源:home.ts


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