将pdf发送到Android FirebaseStorage时出错

时间:2018-09-18 18:40:16

标签: java android firebase firebase-storage

这段代码,我的API是27 在网络上,我只发现有人说它可能是播放服务,但事实并非如此,而且我的代码尽可能接近Firebase文档。我迷路了 logcat错误onFailure

com.google.firebase.storage.StorageException:发生未知错误,请检查HTTP结果代码和服务器响应的内部异常。

上传代码

    private void uploadFile(Uri pdfUri) {
    try {
        Uri file = Uri.fromFile(new File(pdfUri.getEncodedPath().toString()));
        StorageReference riversRef = storageRef.getReference(pdfUri.toString())
                .child("arquivos/").child("arq"+file.getLastPathSegment());
        UploadTask uploadTask = riversRef.putFile(file);
        uploadTask.addOnFailureListener(new OnFailureListener() {
            @Override
            public void onFailure(@NonNull Exception e) {
                Toast.makeText(getContext(), "Falhou", Toast.LENGTH_SHORT).show();
                Log.d("erro ",e.toString());
            }
        }).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
            @Override
            public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                Toast.makeText(getContext(), "Enviado", Toast.LENGTH_SHORT).show();
            }
        });
    }catch (Exception e){
        Toast.makeText(getContext(),"Digite um nome para o arquivo",Toast.LENGTH_SHORT).show();
        textView.setText(e.toString());
    }
}

选择pdf

    private void selectPDF() {
    Intent intent = new Intent();
    intent.setType("application/pdf");
    intent.setAction(Intent.ACTION_GET_CONTENT);//pegando arquivos
    startActivityForResult(intent, 86);
}

0 个答案:

没有答案