这是你可以上传图片到火力地堡存储好运;)
private void uploadFromUri(Uri fileUri) {
Log.d(TAG, "uploadFromUri:src:" + fileUri.toString());
// [START get_child_ref]
// Get a reference to store file at photos/<FILENAME>.jpg
final StorageReference photoRef = storageRef.child("images")
.child(fileUri.getLastPathSegment());
// [END get_child_ref]
// Upload file to Firebase Storage
// [START_EXCLUDE]
showProgressDialog();
// [END_EXCLUDE]
Log.d(TAG, "uploadFromUri:dst:" + photoRef.getPath());
photoRef.putFile(fileUri)
.addOnSuccessListener(this, new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
// Upload succeeded
Log.d(TAG, "uploadFromUri:onSuccess");
// Get the public download URL
mDownloadUrl = taskSnapshot.getMetadata().getDownloadUrl();
Log.d("The Download Url", mDownloadUrl.toString());
// [START_EXCLUDE]
hideProgressDialog();
// updateUI(mAuth.getCurrentUser());
// [END_EXCLUDE]
}
})
.addOnFailureListener(this, new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
// Upload failed
Log.w(TAG, "uploadFromUri:onFailure", exception);
mDownloadUrl = null;
// [START_EXCLUDE]
hideProgressDialog();
Toast.makeText(NewProduct.this, "Error: upload failed",
Toast.LENGTH_SHORT).show();
// updateUI(mAuth.getCurrentUser());
// [END_EXCLUDE]
}
});
}
// [END upload_from_uri]
有错在代码示例中。请参阅http://stackoverflow.com/questions/38278249/update-progress-bar-with-firebase-uploading –
谢谢弗兰克 工作 –
不要感谢我。我是在文档中编写破碎的代码示例的人。 ;-)感谢@qbix(通过提高他的答案)。 –