在上传到Firebase期间,Uri和getData为空对象

时间:2018-11-06 17:00:00

标签: android firebase uri firebase-storage

将捕获图像上传到Firebase时出现此错误。我在一个教程中看到这可能是因为我的手机,但我对此表示高度怀疑。奇怪的是,如果将其添加到Bitmap,则可以显示图像。从URI上载时出现错误的我。

错误:

 Process: com.otw.siliconsmelters, PID: 13538
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=65637, result=-1, data=Intent { act=inline-data (has extras) }} to activity {com.otw.siliconsmelters/com.otw.siliconsmelters.quality_check_steps}: java.lang.IllegalArgumentException: uri cannot be null
    at android.app.ActivityThread.deliverResults(ActivityThread.java:4177)
    at android.app.ActivityThread.handleSendResult(ActivityThread.java:4220)
    at android.app.ActivityThread.-wrap20(ActivityThread.java)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1579)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:163)
    at android.app.ActivityThread.main(ActivityThread.java:6228)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
 Caused by: java.lang.IllegalArgumentException: uri cannot be null
    at com.google.android.gms.common.internal.Preconditions.checkArgument(Unknown Source)
    at com.google.firebase.storage.StorageReference.putFile(com.google.firebase:firebase-storage@@16.0.4:258)
    at com.otw.siliconsmelters.row1.onActivityResult(row1.java:289)
    at android.support.v4.app.FragmentActivity.onActivityResult(FragmentActivity.java:156)
    at android.app.Activity.dispatchActivityResult(Activity.java:7124)

声明:

private StorageReference mStorage;
mStorage = FirebaseStorage.getInstance().getReference();

我要捕获的代码:

 private void showImageChosen() {
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    startActivityForResult(takePictureIntent, CHOOSE_IMAGE);
}

我要上传到firebase的代码:

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == CHOOSE_IMAGE && resultCode == RESULT_OK) {

            Uri uri = data.getData();

            StorageReference filepath = mStorage.child("PictureTest").child("" + System.currentTimeMillis());

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

                }
            }).addOnFailureListener(new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {

                }
            });

    }
}

1 个答案:

答案 0 :(得分:0)

尝试一下:

std::forward