本文整理匯總了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();
}
}
示例2:
const existsFile = (path, filename) =>
FILE.checkFile(path, filename).catch((e) => {
if (e.code === 1) {
return false
}
return Bluebird.reject(e)
})
示例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);
});
});
示例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}`
})
示例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);
});
}
示例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);
})
}
示例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.')
})
})
示例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));
});
});
示例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));
}
示例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));
}