gpt4 book ai didi

android - 从 Firebase-Storage 将图像存储在 Localstorage 中并获取路径

转载 作者:行者123 更新时间:2023-11-29 22:59:06 25 4
gpt4 key购买 nike

我将图像存储在 Firebase 存储中。现在我想从存储中获取图像,将其下载到本地存储并保存路径以备将来使用。

我试过的是:

FirebaseStorage firebaseStorage = FirebaseStorage.getInstance();
StorageReference httpsReference = firebaseStorage.getReferenceFromUrl("gs://****.appspot.com/image_pics/" + userID + ".jpg");

//images are saved with named based on the userid of the user plus an extension of jpg

现在我想使用 httpsReference 下载本地存储中的图像并返回路径(以字符串形式)。

我不知道我应该使用 firebase db 中的存储位置(即 gs//...)还是我想做的事情的 url。请告诉我。

最佳答案

此代码将帮助您将文件保存到本地存储

FirebaseStorage firebaseStorage = FirebaseStorage.getInstance();
StorageReference httpsReference = firebaseStorage.getReferenceFromUrl("gs://****.appspot.com/image_pics/" + userID + ".jpg"); // IF this is working for you

StorageReference  myStorage = storageRef.child("file.txt"); // Use this and provide the reference
File rootPath = new File(Environment.getExternalStorageDirectory(), "file_name");
if(!rootPath.exists()) {
rootPath.mkdirs();
}
final File localFile = new File(rootPath,"imageName.txt");
islandRef.getFile(localFile).addOnSuccessListener(new OnSuccessListener<FileDownloadTask.TaskSnapshot>() {
@Override
public void onSuccess(FileDownloadTask.TaskSnapshot taskSnapshot) {
Log.e("firebase local tem file created created " + localFile.toString());
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
Log.e("firebase ",";local tem file not created created " +exception.toString());
}
});

关于android - 从 Firebase-Storage 将图像存储在 Localstorage 中并获取路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57124838/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com