我在尝试使用Firebase Storage更新文件元数据时遇到此错误。
发送网络请求PATCH https://firebasestorage.googleapis.com/v0/b/rootssahaj.appspot.com/o/notice%2Fthumbs错误java.net.ProtocolException:未知方法'PATCH';必须是[OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE]中的一个
10-16 12:31:04.819 2043-3160/com.rana.sahaj.myyu W/ExponenentialBackoff: network unavailable, sleeping.
10-16 12:31:04.819 2043-3160/com.rana.sahaj.myyu W/NetworkRequest: error sending network request PATCH https://firebasestorage.googleapis.com/v0/b/rootssahaj.appspot.com/o/notice%2Fthumbs
java.net.ProtocolException: Unknown method 'PATCH'; must be one of [OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE]
at java.net.HttpURLConnection.setRequestMethod(HttpURLConnection.java:685)
at com.android.okhttp.internal.http.HttpsURLConnectionImpl.setRequestMethod(HttpsURLConnectionImpl.java:144)
at brq.b(:com.google.android.gms.DynamiteModulesC:242)
at brq.a(:com.google.android.gms.DynamiteModulesC:269)
at brk.onTransact(:com.google.android.gms.DynamiteModulesC:53)
at android.os.Binder.transact(Binder.java:361)
at com.google.android.gms.internal.zzans$zza$zza.zzuj(Unknown Source)
at com.google.android.gms.internal.zzanv.zza(Unknown Source)
at com.google.android.gms.internal.zzanm.zza(Unknown Source)
at com.google.android.gms.internal.zzanm.zzd(Unknown Source)
at com.google.firebase.storage.zzf.run(Unknown Source)
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:841)
更新元数据的代码为:
FirebaseStorage storage = FirebaseStorage.getInstance();
final StorageReference storageRefNonThumbs = storage.getReferenceFromUrl(constants.FIREBASE_STORAGE_URL + "/notice/nonThumbs");
final StorageReference storageRefThumbs = storage.getReferenceFromUrl(constants.FIREBASE_STORAGE_URL + "/notice/thumbs");
UploadTask uploadTaskThumb = storageRefThumbs.child(timestamp + EmailPref).putFile(DOCUri);
final StorageMetadata metadata = new StorageMetadata.Builder()
.setContentType(DocMiMEType)
.build();
storageRefThumbs.updateMetadata(metadata).addOnSuccessListener(new OnSuccessListener<StorageMetadata>() {
@Override
public void onSuccess(StorageMetadata storageMetadata) {
// Updated metadata is in storageMetadata
storageRefNonThumbs.updateMetadata(metadata)
.addOnSuccessListener(new OnSuccessListener<StorageMetadata>() {
@Override
public void onSuccess(StorageMetadata storageMetadata) {
// Updated metadata is in storageMetadata
// Uri downloadUrlNonThumb = taskSnapshot.getDownloadUrl();
// saveData(editText, null, downloadUrlThumb.toString(), mTime, timestamp, null, null, null, downloadUrlNonThumb.toString());
Log.e("SahajLOG98", "Success in MEtaData@@22***");
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
// Uh-oh, an error occurred!
}
});
}
})
这是Android版本<= 4.0 (Ice Cream Sandwich及以下)和Firebase Storage的已知问题。