尝试将图像上传到Firebase时出现网络错误

时间:2020-01-17 15:07:41

标签: java firebase

我正在开发一项活动,该活动允许您从图库中选择图像,然后按一下按钮,它会自动将其上传到Firebase我创建的存储中(称为“ Images /”)。

我不知道错误是在调用实例进行存储时

public class ActivityPredecir extends AppCompatActivity {

    Button btnabirgaleria, btnpredeccion;
    private  FirebaseStorage storage;
    private StorageReference storageReference;
    ImageView imgpredecir;
    public Uri imgurl;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_predecir);

        //
        btnabirgaleria = (Button)findViewById(R.id.btnabrirgaleria);
        imgpredecir = (ImageView)findViewById(R.id.imgpredecir);
        btnpredeccion = (Button)findViewById(R.id.btnprediccion);


        //conexiones y referencia al firebase
        //storage = FirebaseStorage.getInstance("Images");
        //storageReference = storage.getReference();

        storageReference = FirebaseStorage.getInstance().getReference("images");
        //FirebaseStorage storage = FirebaseStorage.getInstance("gs://subirfoto-f2959.appspot.com/Images");

        btnabirgaleria.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Filechoser();
            }
        });

        btnpredeccion.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Fileuploader();
            }
        });

    }

或者如果上传图片的方法出错

private  void Fileuploader(){

    StorageReference reference = storageReference.child("foto"+"."+getExtension(imgurl));

    reference.putFile(imgurl)
            .addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
                @Override
                public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                    // Get a URL to the uploaded content
                    //Uri downloadUrl = taskSnapshot.getDownloadUrl();
                    Toast.makeText(ActivityPredecir.this,"Imagen subida",Toast.LENGTH_LONG).show();
                }
            })
            .addOnFailureListener(new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception exception) {
                    // Handle unsuccessful uploads
                    // ...
                }
            });


}

按下按钮上传图像时,出现以下错误:

at com.google.firebase.storage.UploadTask.serverStateValid(com.google.firebase:firebase-storage@@16.0.4:320)
    at com.google.firebase.storage.UploadTask.shouldContinue(com.google.firebase:firebase-storage@@16.0.4:289)
    at com.google.firebase.storage.UploadTask.run(com.google.firebase:firebase-storage@@16.0.4:203)
    at com.google.firebase.storage.StorageTask.lambda$getRunnable$7(com.google.firebase:firebase-storage@@16.0.4:1106)
    at com.google.firebase.storage.StorageTask$$Lambda$12.run(Unknown Source:2)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
    at java.lang.Thread.run(Thread.java:764)
 Caused by: java.io.IOException: {  "error": {    "code": 404,    "message": "Not Found.  Could not access bucket tomarfotos-ee957.appspot.com",    "status": "ACCESS_BUCKET"  }}
    at com.google.firebase.storage.network.NetworkRequest.parseResponse(com.google.firebase:firebase-storage@@16.0.4:455)
    at com.google.firebase.storage.network.NetworkRequest.parseErrorResponse(com.google.firebase:firebase-storage@@16.0.4:435)
    at com.google.firebase.storage.network.NetworkRequest.processResponseStream(com.google.firebase:firebase-storage@@16.0.4:426)
    at com.google.firebase.storage.network.NetworkRequest.performRequest(com.google.firebase:firebase-storage@@16.0.4:280)
    at com.google.firebase.storage.network.NetworkRequest.performRequest(com.google.firebase:firebase-storage@@16.0.4:294)
    at com.google.firebase.storage.internal.ExponentialBackoffSender.sendWithExponentialBackoff(com.google.firebase:firebase-storage@@16.0.4:65)
    at com.google.firebase.storage.internal.ExponentialBackoffSender.sendWithExponentialBackoff(com.google.firebase:firebase-storage@@16.0.4:57)
    at com.google.firebase.storage.UploadTask.sendWithRetry(com.google.firebase:firebase-storage@@16.0.4:457)
    at com.google.firebase.storage.UploadTask.beginResumableUpload(com.google.firebase:firebase-storage@@16.0.4:257)
    at com.google.firebase.storage.UploadTask.run(com.google.firebase:firebase-storage@@16.0.4:198)

0 个答案:

没有答案