存储异常

时间:2019-02-25 12:13:09

标签: android firebase firebase-storage

当我尝试从Firebase下载文件时,它显示此错误:

 02-25 17:29:47.377 2297-2297/cyber.com.obsi.blackorn E/System: elements.add : /mnt/asec/cyber.com.obsi.blackorn-2/base.apk  /mnt/asec/cyber.com.obsi.blackorn-2/base.apk   /mnt/asec/cyber.com.obsi.blackorn-2/base.apk
    02-25 17:29:49.514 2297-2297/cyber.com.obsi.blackorn E/MediaPlayer-JNI: QCMediaPlayer mediaplayer NOT present
    02-25 17:30:07.323 2297-2413/cyber.com.obsi.blackorn E/StorageException: StorageException has occurred.
        User does not have permission to access this object.
         Code: -13021 HttpResult: 403
    02-25 17:30:07.331 2297-2413/cyber.com.obsi.blackorn E/StorageException: {  "error": {    "code": 403,    "message": "Permission denied. Could not perform this operation"  }}
        java.io.IOException: {  "error": {    "code": 403,    "message": "Permission denied. Could not perform this operation"  }}
            at com.google.firebase.storage.network.NetworkRequest.parseResponse(com.google.firebase:firebase-storage@@16.0.5:455)
            at com.google.firebase.storage.network.NetworkRequest.parseErrorResponse(com.google.firebase:firebase-storage@@16.0.5:435)
            at com.google.firebase.storage.network.NetworkRequest.processResponseStream(com.google.firebase:firebase-storage@@16.0.5:426)
            at com.google.firebase.storage.network.NetworkRequest.performRequest(com.google.firebase:firebase-storage@@16.0.5:280)
            at com.google.firebase.storage.network.NetworkRequest.performRequest(com.google.firebase:firebase-storage@@16.0.5:294)
            at com.google.firebase.storage.internal.ExponentialBackoffSender.sendWithExponentialBackoff(com.google.firebase:firebase-storage@@16.0.5:65)
            at com.google.firebase.storage.internal.ExponentialBackoffSender.sendWithExponentialBackoff(com.google.firebase:firebase-storage@@16.0.5:57)
            at com.google.firebase.storage.GetDownloadUrlTask.run(com.google.firebase:firebase-storage@@16.0.5:71)
            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:818)
    02-25 17:30:18.884 2297-2437/cyber.com.obsi.blackorn E/StorageException: StorageException has occurred.
        User does not have permission to access this object.
         Code: -13021 HttpResult: 403
    02-25 17:30:18.885 2297-2437/cyber.com.obsi.blackorn E/StorageException: {  "error": {    "code": 403,    "message": "Permission denied. Could not perform this operation"  }}
        java.io.IOException: {  "error": {    "code": 403,    "message": "Permission denied. Could not perform this operation"  }}
            at com.google.firebase.storage.network.NetworkRequest.parseResponse(com.google.firebase:firebase-storage@@16.0.5:455)
            at com.google.firebase.storage.network.NetworkRequest.parseErrorResponse(com.google.firebase:firebase-storage@@16.0.5:435)
            at com.google.firebase.storage.network.NetworkRequest.processResponseStream(com.google.firebase:firebase-storage@@16.0.5:426)
            at com.google.firebase.storage.network.NetworkRequest.performRequest(com.google.firebase:firebase-storage@@16.0.5:280)
            at com.google.firebase.storage.network.NetworkRequest.performRequest(com.google.firebase:firebase-storage@@16.0.5:294)
            at com.google.firebase.storage.internal.ExponentialBackoffSender.sendWithExponentialBackoff(com.google.firebase:firebase-storage@@16.0.5:65)
            at com.google.firebase.storage.internal.ExponentialBackoffSender.sendWithExponentialBackoff(com.google.firebase:firebase-storage@@16.0.5:57)
            at com.google.firebase.storage.GetDownloadUrlTask.run(com.google.firebase:firebase-storage@@16.0.5:71)
            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:818)'

请在下面找到程序,我也更新了Firebase中的规则

package cyber.com.obsi.blackorn;

import android.app.DownloadManager;
import android.content.Context;
import android.content.Intent;
import android.graphics.PorterDuff;
import android.net.Uri;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.SeekBar;
import android.widget.TextView;

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.FirebaseStorage;
import com.google.firebase.storage.StorageReference;

import static android.os.Environment.DIRECTORY_DOWNLOADS;

public class Showdata extends AppCompatActivity {

    private android.widget.VideoView videoView;
    private android.widget.MediaController mediaController;
    private FirebaseAuth firebaseAuth;
    FirebaseStorage firebaseStorage;
    StorageReference storageReference;
    StorageReference ref;
    private TextView txtview;
    Intent intent=getIntent();
    private String url;
    int reqcode; 

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_showdata);
         videoView = findViewById(R.id.videoView);
         txtview =findViewById(R.id.downldtv);
        firebaseAuth =FirebaseAuth.getInstance();    

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

        Intent mintent= getIntent();

        reqcode=mintent.getIntExtra("reqcode",0);

        if(reqcode==0)
        {
            url="https://firebasestorage.googleapis.com/v0/b/blackcorncyber-aa14f.appspot.com/o/vlog.mp4?alt=media&token=3892d367-e151-4982-b4b5-38e62effb21d";

        }
        if(reqcode==1)
        {    
            url= "https://firebasestorage.googleapis.com/v0/b/blackcorncyber-aa14f.appspot.com/o/y2mate.com%20-%20what_is_cyber_security_introduction_to_cyber_security_cyber_security_training_edureka_ooJSgsB5fIE_360p.mp4?alt=media&token=35e7e62d-46ec-4154-914b-652107e2b3ec";
        }

        String fullScreen =  getIntent().getStringExtra("fullScreenInd");
        if("y".equals(fullScreen)){
            getWindow().setFlags(android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN,
         android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN);
            getSupportActionBar().hide();
        }  

        android.net.Uri videoUri = android.net.Uri.parse(url);

        videoView.setVideoURI(videoUri);

        mediaController = new FullScreenMediaController(this);
        mediaController.setAnchorView(videoView);

        videoView.setMediaController(mediaController);
        videoView.start();    
    }

    public void download()
    {    
        storageReference = firebaseStorage.getInstance().getReference();
        ref =storageReference.child("Ashumatlabcerti.pdf");
        ref.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
            @Override
            public void onSuccess(Uri uri) {
                String url=uri.toString();
                downloadfiles(Showdata.this,"Ashumatlabcerti","pdf",DIRECTORY_DOWNLOADS,url);    

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

            }
        });   
    }
    public void downloadfiles(Context context,String filename,String fileextension,String destinationdirectory,String url)
    {    
        DownloadManager downloadManager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);

        Uri uri=Uri.parse(url);
        DownloadManager.Request request= new DownloadManager.Request(uri);    
        request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
        request.setDestinationInExternalFilesDir(context,destinationdirectory,filename+fileextension);
        downloadManager.enqueue(request);  
    }
}

0 个答案:

没有答案