Nativescript - 文件系统覆盖在 Android 上不起作用

Nativescript - file system overwrite not working on Android

我是 NativeScript 的新手。

我正在使用 nativescript-plugin-firebase 下载用户的照片并将其保存到 /data/user/0/{APP_ID}/files/telerik-logo-downloaded.png

Firebase 存储本机 API 示例:

var fs = require("tns-core-modules/file-system");

// let's first determine where we'll create the file using the 'file- system' module
var documents = fs.knownFolders.documents();
var logoPath = documents.path + "/telerik-logo-downloaded.png";

// this will create or overwrite a local file in the app's documents folder
var localLogoFile = documents.getFile("telerik-logo-downloaded.png");

// now download the file with either of the options below:
firebase.storage.downloadFile({
  bucket: 'gs://n-plugin-test.appspot.com',
  remoteFullPath: 'uploads/images/telerik-logo-uploaded.png',
  localFile: fs.File.fromPath(logoPath),
  localFullPath: logoPath
}).then(
  function (uploadedFile) {
    console.log("File downloaded to the requested location");
  },
  function (error) {
    console.log("File download error: " + error);
  }
);

当发生变化时(例如用户上传一张新照片),我将使用 Firebase Storage Native API 下载照片并覆盖现有照片。

var localLogoFile = documents.getFile("telerik-logo-downloaded.png");

上面的代码应该覆盖本地文件(如果存在)。

结果,新照片将显示在 iOS 而不是 Android。 Android还是老照片

有人可以帮忙吗?谢谢~

我想你的问题是你加载 imageSource 的方式。

它应该已经覆盖了文件,试试这个

img.src = imageSource.fromFile(logoPath)

而不是

img.src = logoPath

希望对您有所帮助!干杯!

使用 Android 如果图像再次相同 url 则不会刷新。尝试将图像源设置为 null,然后再次将其设置回您的路径。