本文整理汇总了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));
});