我正在尝试将扫描的文件(使用android文档扫描库)存储到FirebaseStorage,但是我遇到了存储异常,我尝试了所有答案,但没有一个适合我。
我正在尝试将扫描的文件(使用android文档扫描库)存储到FirebaseStorage,但是我遇到了存储异常,我尝试了所有答案,但没有一个适合我。我可以在firebase Realtime数据库中插入数据,但是当调用函数上传文件时,出现以下异常:
错误如下:
E/UploadTask: could not locate file for uploading:content://media/external/images/media/47608
E/StorageException: StorageException has occurred.
An unknown error occurred, please check the HTTP result code and inner exception for server response.
Code: -13000 HttpResult: 0
E/StorageException: No entry for content://media/external/images/media/47608
java.io.FileNotFoundException: No entry for content://media/external/images/media/47608
at android.database.DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(DatabaseUtils.java:149)
at android.content.ContentProviderProxy.openTypedAssetFile(ContentProviderNative.java:692)
at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1137)
at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:958)
at android.content.ContentResolver.openInputStream(ContentResolver.java:678)
at com.google.firebase.storage.UploadTask.<init>(com.google.firebase:firebase-storage@@16.0.5:118)
at com.google.firebase.storage.StorageReference.putFile(com.google.firebase:firebase-storage@@16.0.5:260)
at io.zentechgh.dms.mobile.app.fragment.AddDocumentFragment.uploadDocumentFile(AddDocumentFragment.java:362)
at io.zentechgh.dms.mobile.app.fragment.AddDocumentFragment.access$000(AddDocumentFragment.java:60)
at io.zentechgh.dms.mobile.app.fragment.AddDocumentFragment$2.onComplete(AddDocumentFragment.java:334)
at com.google.android.gms.tasks.zzj.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5763)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
E/StorageException: StorageException has occurred.
An unknown error occurred, please check the HTTP result code and inner exception for server response.
Code: -13000 HttpResult: 0
下面是上传文档的代码块:
// method to upload the document file only
private void uploadDocumentFile(){
final StorageReference documentFileRef = FirebaseStorage.getInstance()
.getReference(" Documents /");
if(documentUri != null){
documentFileRef.putFile(documentUri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
documentFileRef.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
// getting image uri and converting into string
Uri downloadUrl = uri;
documentUrl = downloadUrl.toString();
}
});
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
// display an error message
Toast.makeText(applicationContext, " Failed : " + e.getMessage(), Toast.LENGTH_LONG).show();
}
}).addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {
@Override
public void onProgress(UploadTask.TaskSnapshot taskSnapshot) {
double progress = (100.0*taskSnapshot.getBytesTransferred()/taskSnapshot
.getTotalByteCount());
progressDialog.setMessage("Uploaded "+(int)progress+"%");
}
});;
}
}
我想成功将文件上传到存储。