本文整理匯總了TypeScript中@ionic-native/file.File.copyFile方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript File.copyFile方法的具體用法?TypeScript File.copyFile怎麽用?TypeScript File.copyFile使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類@ionic-native/file.File
的用法示例。
在下文中一共展示了File.copyFile方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: 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);
});
}
示例2: 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}`
})
示例3: Observable
return new Observable(observer => {
this.file.copyFile(this.file.dataDirectory, oldFilePath, this.file.dataDirectory, newFilePath)
.then((newFile) => observer.next(newFile))
.catch((error) => observer.error(error));
});