尝试从存储

时间:2016-09-16 13:53:31

标签: android firebase firebase-realtime-database firebase-storage

我有一个按钮来上传我的照片。它将在根目录上创建一个名为userID的文件夹。在那里会有图片。一切都很好。所以现在我想用oncreate方法下载图片,用户在浏览他的个人资料时看到他的照片!但它不工作它总是给我404错误。有人知道如何调用该文件进行下载吗?

上载:

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        Intent i = getIntent();
        String userID = i.getStringExtra("UID");

        if(requestCode == GALLERY_INTENT && resultCode == RESULT_OK){

            mProgressDialog.setMessage("Lädt hoch...");
            mProgressDialog.show();

            Uri uri = data.getData();

            StorageReference childref = mStorage.child(userID).child(uri.getLastPathSegment());

            childref.putFile(uri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
                @Override
                public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {

                    mProgressDialog.dismiss();
                    Uri downloadUri = taskSnapshot.getDownloadUrl();
                    Picasso.with(Profil.this).load(downloadUri).fit().centerCrop().into(mImageView);
                    Toast.makeText(Profil.this, "Hochladen Erfolgreich!", Toast.LENGTH_LONG).show();

                }
            });
        }
}

下载:

mStorage.child("2CZ4ak9TgFSNeHACowSEc5QiUBG3/28881.jpeg").getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
            @Override
            public void onSuccess(Uri uri) {
                Toast.makeText(Profil.this, "Download Succesfully", Toast.LENGTH_LONG).show();
            }
        }).addOnFailureListener(new OnFailureListener() {
            @Override
            public void onFailure(@NonNull Exception exception) {
                Toast.makeText(Profil.this, "Download failed!", Toast.LENGTH_LONG).show();
            }
        });

错误讯息:

09-16 15:52:21.909 30538-31025/highelo.drivetogether E/StorageException: StorageException has occurred.
                                                                         Object does not exist at location.
                                                                          Code: -13010 HttpResult: 404
09-16 15:52:21.909 30538-31025/highelo.drivetogether E/StorageException: {  "error": {    "code": 404,    "message": "Not Found.  Could not get object"  }}
                                                                         java.io.IOException: {  "error": {    "code": 404,    "message": "Not Found.  Could not get object"  }}
                                                                             at bzr.a(:com.google.android.gms.DynamiteModulesC:424)
                                                                             at bzr.a(:com.google.android.gms.DynamiteModulesC:1404)
                                                                             at bzl.onTransact(:com.google.android.gms.DynamiteModulesC:53)
                                                                             at android.os.Binder.transact(Binder.java:361)
                                                                             at com.google.android.gms.internal.zzamg$zza$zza.zztj(Unknown Source)
                                                                             at com.google.android.gms.internal.zzamj.zza(Unknown Source)
                                                                             at com.google.android.gms.internal.zzama.zza(Unknown Source)
                                                                             at com.google.android.gms.internal.zzama.zzd(Unknown Source)
                                                                             at com.google.firebase.storage.zzb.run(Unknown Source)
                                                                             at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
                                                                             at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
                                                                             at java.lang.Thread.run(Thread.java:841)

0 个答案:

没有答案