gpt4 book ai didi

android - 下载时出现 Firebase StorageException

转载 作者:搜寻专家 更新时间:2023-11-01 08:26:49 26 4
gpt4 key购买 nike

我一直在寻找这个问题,但我没有在这里找到任何解决方案。我的问题是,当我将新项目发布到 firebase 存储时,一切正常,但是当我尝试下载它时,目录文件夹已成功创建,但文件未下载,因为它向我显示此错误异常:

com.google.firebase.storage.StorageException: Object does not exist at location

我的代码在这里:

  @Override
public void onButtonDownloadClick(View view, final int position) {
String name = list.get(position).getRemoteName();


File storagePath = new File(Environment.getExternalStorageDirectory(), "FromFiles");
// Create direcorty if not exists
if(!storagePath.exists()) {
storagePath.mkdirs();
}

final File myFile = new File(storagePath, list.get(position).getRemoteName());


islandRef = storageReference.child(uid).child("files").child(name);


islandRef.getFile(myFile).addOnSuccessListener(new OnSuccessListener<FileDownloadTask.TaskSnapshot>() {
@Override
public void onSuccess(FileDownloadTask.TaskSnapshot taskSnapshot) {
// Local temp file has been created
Toast.makeText(getActivity(), "Succeed", Toast.LENGTH_LONG).show();
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
// Handle any errors
Toast.makeText(getActivity(), exception.toString(), Toast.LENGTH_LONG).show();
}
});

}
});

当我按下按钮时,应该下载文件,但只创建了目录。

最佳答案

这是 firebase 下载的工作示例并检查下载路径,对象应该存在于存储桶中。

// Initialize Storage
//storage
mStorage = FirebaseStorage.getInstance("gs://<bucket_name>");
mStorageRef = mStorage.getReference();

final StorageReference downloadRef;
downloadRef = mStorageRef.getRoot().child(downloadPath);

try {
File output = new File(Environment.getExternalStorageDirectory() + File.separator + Config.MY_VIDEOS_PATH);
if (!output.exists()) {
output.mkdir();
}
localFile = new File(output, downloadId);
} catch (Exception e) {
e.printStackTrace();
}


// Download and get total bytes
downloadRef.getFile(localFile)
.addOnProgressListener(new OnProgressListener<FileDownloadTask.TaskSnapshot>() {
@Override
public void onProgress(FileDownloadTask.TaskSnapshot taskSnapshot) {
showProgressNotification(1,title, "",
taskSnapshot.getBytesTransferred(),
taskSnapshot.getTotalByteCount());
}
})
.addOnSuccessListener(new OnSuccessListener<FileDownloadTask.TaskSnapshot>() {
@Override
public void onSuccess(FileDownloadTask.TaskSnapshot taskSnapshot) {
Log.d(TAG, "download:SUCCESS");
// Send success broadcast with number of bytes downloaded
broadcastDownloadFinished(downloadPath, taskSnapshot.getTotalByteCount());
showDownloadFinishedNotification(downloadPath, (int) taskSnapshot.getTotalByteCount());

// Mark task completed
taskCompleted();
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
Log.w(TAG, "download:FAILURE", exception);
Log.w(TAG, "download:FAILURE", exception.getCause());

// Send failure broadcast
broadcastDownloadFinished(downloadPath, -1);
showDownloadFinishedNotification(downloadPath, -1);

// Mark task completed
taskCompleted();
}
});

让我们假设你的 image.jpg 在 photos 文件夹然后是 downloadPath photos/image.jpg

关于android - 下载时出现 Firebase StorageException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44178128/

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