【问题标题】:How to delete a NativeScript ImageAsset created with nativescript-camera?如何删除使用 nativescript-camera 创建的 NativeScript ImageAsset?
【发布时间】:2018-05-01 15:08:17
【问题描述】:
import { takePicture, CameraOptions } from "nativescript-camera";

CameraOptions 允许将saveToGallery 设置为false。 但是,当我使用takePicture 创建ImageAsset 时,图像会存储在我的Android 设备的内部存储> Android > 数据> org.nativescript.appname > 文件中。资产(asset.android) 的控制台输出为:

/storage/emulated/0/Android/data/org.nativescript.HelloWorld/files/NSIMG_20180430_131826.jpg

我使用imageSource.ImageSource().fromAssetimageSource.ImageSource.saveToFile 将图像保存在某个已知位置,现在我想从我的设备中删除源文件NSIMG_20180430_131826.jpg

有人可以帮忙吗?

【问题讨论】:

  • 存在一个已知错误,在某些手机上无法设置saveToGallery,因此默认为true,github问题为here
  • @mast3rd3mon 该文件没有出现在“图库”中(以及使用设备拍摄的其他照片),但它保存在应用程序本地的文件夹中。问题是我无法以编程方式“看到”这个本地文件夹,也无法使用绝对路径删除文件。

标签: angular nativescript


【解决方案1】:

你可以试试下面的代码:

try {
    //get file
    const path = "/storage/emulated/0/Android/data/org.nativescript.HelloWorld/files/NSIMG_20180430_131826.jpg";

    const pathArray = path.split('/');
    //get file name
    const fileToRemovePath = pathArray[pathArray.length - 1];
    //remove the file, try adding 'files' as a folder name
    let folder = fs.knownFolders.currentApp().getFolder("yourfoldernamewhereyoucopied");
    const fileToRemove = folder.getFile(fileToRemovePath);
    if(fileToRemove) {
        //delete it
        await fileToRemove.remove();
    }
} catch (e) {
    //dialogs.alert('Couldnot delete the file');
}

你也需要 import fs

import * as fs from "file-system";

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-13
    • 2019-08-07
    • 2016-07-24
    • 2016-01-27
    • 2020-10-15
    • 1970-01-01
    相关资源
    最近更新 更多