我想在android應用程序的firebase
存儲下載圖像。如何在Firebase存儲上下載圖像?
這是我的形象
我嘗試這一點,但它不工作
storageRef.child("1/1.jpg").getDownloadUrl().getResult();
我想在android應用程序的firebase
存儲下載圖像。如何在Firebase存儲上下載圖像?
這是我的形象
我嘗試這一點,但它不工作
storageRef.child("1/1.jpg").getDownloadUrl().getResult();
試試這個
// Create a storage reference from our app
StorageReference storageRef = storage.getReferenceFromUrl("gs://<your-bucket-name>");
// Create a reference with an initial file path and name
StorageReference pathReference = storageRef.child("users/me/yourpics.png");
storageRef.child("users/me/yourpics.png").getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
// Got the download URL for 'users/me/profile.png'
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
// Handle any errors
}
});
**用戶/我/ **是什麼?爲什麼**。png **? –
StorageReference pathReference = storageRef.child(「images/stars.jpg」); –
要下載文件,首先創建一個雲存儲對您要下載的文件的引用。
您可以通過將子路徑附加到存儲根目錄來創建引用,也可以從引用Cloud Storage中的對象的現有gs://
或https:// URL
創建引用。
// Create a storage reference from our app
StorageReference storageRef = storage.getReference();
// Create a reference with an initial file path and name
StorageReference pathReference = storageRef.child("images/stars.jpg");
images
是根的孩子。
storageRef.child("images/stars.jpg").getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
// Got the download URL for 'users/me/profile.png'
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
// Handle any errors
}
});
@ErsinGülbahar嘗試查看您在onFailure中遇到的錯誤。 –
// Create a storage reference from our app
StorageReference storageRef = storage.getReference();
// Create a reference to a file from a Google Cloud Storage URI
StorageReference gsReference =
storage.getReferenceFromUrl("gs://bucket/images/stars.jpg");
//Download file in Memory
StorageReference islandRef = storageRef.child("images/island.jpg");
final long ONE_MEGABYTE = 1024 * 1024;
islandRef.getBytes(ONE_MEGABYTE).addOnSuccessListener(new
OnSuccessListener<byte[]>() {
@Override
public void onSuccess(byte[] bytes) {
// Data for "images/island.jpg" is returns, use this as needed
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
// Handle any errors
}
});
https://firebase.google.com/docs/storage/android/download - 文件 – Ibrahim
什麼是不工作的代碼? –