我正在尝试创建应用程序Firebase图片上传。
干草伙伴,我在获取会话的图片下载网址方面遇到一些问题。
我的Firebase版本是:
implementation 'com.google.firebase:firebase-auth:16.0.5'
implementation 'com.google.firebase:firebase-storage:16.0.5'
我的下载URL得到的代码是:
String profileimageurl = taskSnapshot.getMetadata().getReference().getDownloadUrl().toString();
如何解决此问题,我的错误是:
java.io.FileNotFoundException: /com.google.android.gms.tasks.zzu@527ce2f (No such file or directory)
I/Glide: Root cause (2 of 3)
java.io.FileNotFoundException: open failed: ENOENT (No such file or directory)
I/Glide: Root cause (3 of 3)
java.io.FileNotFoundException: open failed: ENOENT (No such file or directory)
图片已上传到我的Firebase存储中,但无法访问
答案 0 :(得分:1)
最后,
private void uriImageUpload() {
final StorageReference storageReference = FirebaseStorage.getInstance().getReference("myprofile/" + System.currentTimeMillis() + ".jpg");
if (urimageurl != null) {
storageReference.putFile(urimageurl)
.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Toast.makeText(getApplicationContext(), "Image Uploaded Successfully", Toast.LENGTH_LONG).show();
//TODO Here is the problem
// profileimageurl = taskSnapshot.getDownloadUrl().toString();
String myprofileurl = taskSnapshot.getMetadata().getReference().getDownloadUrl().toString();
Log.d(TAG, "Profile image uploading url " + myprofileurl);
storageReference.getDownloadUrl().addOnCompleteListener(new OnCompleteListener<Uri>() {
@Override
public void onComplete(@NonNull Task<Uri> task) {
profileimageurl=task.getResult().toString();
Log.i("URL",profileimageurl);
}
});
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(getApplicationContext(), "Image Uploading was failed", Toast.LENGTH_LONG).show();
}
});
}
}
只需添加
storageReference.getDownloadUrl().addOnCompleteListener(new OnCompleteListener<Uri>() {
@Override
public void onComplete(@NonNull Task<Uri> task) {
profileimageurl=task.getResult().toString();
Log.i("URL",profileimageurl);
}
});
就这些。