我正在尝试更新Firebase存储上的照片。
存储规则是公开的,所有图书馆都是最新的。
对于存储桶我使用的是我的firebase控制台。
致命异常:
java.lang.IllegalArgumentException:提供的bucketname不是 可用于此项目。在 com.moose.android.AddPostActivity.onClick(AddPostActivity.java:163)
Bitmap bitmap = imageBitmap;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 80, baos);
byte[] data = baos.toByteArray();
FirebaseStorage mFirebaseStorage = FirebaseStorage.getInstance();
***StorageReference mStorageRef = mFirebaseStorage.getReferenceFromUrl("gs://bucketname.appspot.com"); //line 163***
final StorageReference photoRef = mStorageRef.child("posts_images/mooseImg" + getCurrentDateTime() + ".jpg");
UploadTask uploadTask = photoRef.putBytes(data);
uploadTask.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
// Handle unsuccessful uploads
}
}).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
// taskSnapshot.getMetadata() contains file metadata such as size, content-type, and download URL.
Uri downloadUrl = taskSnapshot.getDownloadUrl();
Firebase createNewPost = new Firebase(FirebaseURL);
Firebase alanRef = createNewPost.push();
Map<String, Object> nickname = new HashMap<String, Object>();
nickname.put("createdAt", getCurrentDateTime());
nickname.put("imageURL", downloadUrl.toString());
/*nickname.put("latitude", 20.1814);
nickname.put("longitude", 72.1781);*/
nickname.put("latitude", prefs.getLatitude());
nickname.put("longitude", prefs.getLongitude());
nickname.put("objectId", alanRef.getKey());
nickname.put("ownerId", prefs.getUserUId());
nickname.put("postText", editTextNewPostMsg.getText().toString());
nickname.put("replies", 0);
nickname.put("reportCount", 0);
nickname.put("score", 0);
nickname.put("updatedAt", getCurrentDateTime());
alanRef.setValue(nickname, new Firebase.CompletionListener() {
@Override
public void onComplete(FirebaseError firebaseError, Firebase firebase) {
dismissProgressDialog();
Toast.makeText(getApplicationContext(), "your post have been added.", Toast.LENGTH_LONG).show();
finish();
}
});
// LogUtil.debug(&#34; StorageRef =&#34; + mStorageRef); } });
答案 0 :(得分:-1)
它应该在您的google-services.json文件中,标记为&#34; storage_bucket&#34;
&#34; project_info&#34;:{ &#34; project_number&#34;:&#34; 816275527980&#34;, &#34; firebase_url&#34;:&#34; https://project-8693710910123456789.firebaseio.com&#34;, &#34; project_id&#34;:&#34; project-8693710910123456789&#34;, &#34; storage_bucket&#34;:&#34; project-8693710910123456789.appspot.com&#34; },