对象在该位置不存在。代码:-13010 Http结果:404

时间:2019-02-28 04:38:18

标签: android firebase-authentication firebase-storage

  

当我尝试从Firebase下载文件时,我得到了

02-28 09:47:41.055 31045-31045 / cyber.com.obsi.firebase_tutorial E / System:elements.add:/mnt/asec/cyber.com.obsi.firebase_tutorial-1/base.apk / mnt /asec/cyber.com.obsi.firebase_tutorial-1/base.apk /mnt/asec/cyber.com.obsi.firebase_tutorial-1/base.apk     02-28 09:48:35.994 31045-31285 / cyber.com.obsi.firebase_tutorial E / StorageException:发生StorageException。         对象在该位置不存在。          代码:-13010 HTTP结果:404     02-28 09:48:35.995 31045-31285 / cyber.com.obsi.firebase_tutorial E / StorageException:发生StorageException。         对象在该位置不存在。          代码:-13010 HTTP结果:404     02-28 09:48:35.995 31045-31045 / cyber.com.obsi.firebase_tutorial E / firebase:;未创建本地tem文件com.google.firebase.storage.StorageException:该位置不存在对象。

  

这是Java代码

package cyber.com.obsi.firebase_tutorial;

import android.content.Intent;
import android.net.Uri;
import android.os.Environment;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.MediaController;
import android.widget.TextView;
import android.widget.VideoView;

import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.storage.FileDownloadTask;
import com.google.firebase.storage.FirebaseStorage;
import com.google.firebase.storage.StorageReference;

import java.io.File;
import java.io.IOException;

public class SecondActivity extends AppCompatActivity {
    private FirebaseAuth firebaseAuth;

    FirebaseStorage firebaseStorage;
    StorageReference storageReference,pathreference;
    private Button plybtn;
    private Uri videoUri;
    private TextView download;
    private  VideoView videoView;
    MediaController mediac;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);
        plybtn=findViewById(R.id.plybtn);
        download=findViewById(R.id.dwnlpdf);
        videoView =findViewById(R.id.secondVideoview);



        plybtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                mediac= new MediaController(SecondActivity.this);
                mediac.setAnchorView(videoView);
                videoUri = Uri.parse("https://firebasestorage.googleapis.com/v0/b/fir-tutorial-618f4.appspot.com/o/vlog.mp4?alt=media&token=9ff8bffe-0aee-43e6-a36a-54c3eb15273f");
                videoView.setVideoURI(videoUri);
                videoView.start();
                firebaseAuth =FirebaseAuth.getInstance();
            }
        });

        download.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                downloadFile();

            }
        });

    }


     private void Logout()
     {
         firebaseAuth.signOut();
        finish();
        startActivity(new Intent(SecondActivity.this,MainActivity.class));

     }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu,menu);
        return true;
    }
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        switch (item.getItemId()){

            case   R.id.logoutmenu :{


                Logout();
                break;
            }

            case R.id.profile:{


                startActivity(new Intent(SecondActivity.this,profileActivity.class));
                break;
            }



        }
        return super.onOptionsItemSelected(item);
    }

    private void downloadFile() {
        FirebaseStorage storage = FirebaseStorage.getInstance();
        StorageReference storageRef = storage.getReferenceFromUrl("gs://fir-tutorial-618f4.appspot.com/Ashumatlabcerti.pdf");
        StorageReference  islandRef = storageRef.child("Ashumatlabcerti.pdf");

        File rootPath = new File(Environment.getExternalStorageDirectory(), "Ashumatlabcerti.pdf");
        if(!rootPath.exists()) {
            rootPath.mkdirs();
        }

        final File localFile = new File(rootPath,"Ashumatlabcerti.pdf");

        islandRef.getFile(localFile).addOnSuccessListener(new OnSuccessListener<FileDownloadTask.TaskSnapshot>() {
            @Override
            public void onSuccess(FileDownloadTask.TaskSnapshot taskSnapshot) {
                Log.e("firebase ",";local tem file created  created " +localFile.toString());
                //  updateDb(timestamp,localFile.toString(),position);
            }
        }).addOnFailureListener(new OnFailureListener() {
            @Override
            public void onFailure(@NonNull Exception exception) {
                Log.e("firebase ",";local tem file not created  created " +exception.toString());
            }
        });
    }





    }

0 个答案:

没有答案