customApp= new FirebaseApp(getApplicationContext(),"My News",<to be filled>);
storage = FirebaseStorage.getInstance(customApp);
我是firebase的新用戶,自定義應用程序的確切用途是什麼。Firebase自定義應用程序設置
我想創建一個自定義應用程序,使用Firebase將大文件上傳到谷歌雲存儲。這是爲我推薦的自定義應用程序嗎?
customApp= new FirebaseApp(getApplicationContext(),"My News",<to be filled>);
storage = FirebaseStorage.getInstance(customApp);
我是firebase的新用戶,自定義應用程序的確切用途是什麼。Firebase自定義應用程序設置
我想創建一個自定義應用程序,使用Firebase將大文件上傳到谷歌雲存儲。這是爲我推薦的自定義應用程序嗎?
如果你是新的火力地堡,機會是你不需要定製FirebaseApp
。相反,只需使用FirebaseStorage.getInstance().getReference()
,如Firebase Storage documentation所示。
不需要使用customApp;
簡單,我們可以使用
storage = FirebaseStorage.getInstance("gs://<Google cloud storage bucket name>");
如果我們想要存儲的引用然後
mStorageRef = storage.getReferenceFromUrl("gs://<Google cloud storage bucket name>");
@Override
public void onCreate() {
super.onCreate();
FirebaseOptions options = new FirebaseOptions.Builder()
.setApiKey("AI...3LnY")
.setStorageBucket("gs://f...t")
.setApplicationId("1:356....:android:f......232")
.build();
customApp = FirebaseApp.initializeApp(getApplicationContext(),options,"MyApp");
//storage
storage = FirebaseStorage.getInstance(customApp);`enter code here`
}
偉大的答案弗蘭克van puffelen先生。 它的工作對我來說(進口從谷歌Cloud Storage值。)
mStorageRef = FirebaseStorage.getInstance("gs://c......s").getReference();
從谷歌雲存儲的文件下載到使用火力本地設備。
final StorageReference downloadRef;
downloadRef = mStorageRef.getRoot().child(downloadPath);
try {
File output = new File(Environment.getExternalStorageDirectory() + File.separator + Config.MY_VIDEOS_PATH);
if (!output.exists()) {
output.mkdir();
}
localFile = new File(output, downloadId);
} catch (Exception e) {
e.printStackTrace();
}
// Download and get total bytes
downloadRef.getFile(localFile)
.addOnProgressListener(new OnProgressListener<FileDownloadTask.TaskSnapshot>() {
@Override
public void onProgress(FileDownloadTask.TaskSnapshot taskSnapshot) {
showProgressNotification(title, "",
taskSnapshot.getBytesTransferred(),
taskSnapshot.getTotalByteCount());
}
})
.addOnSuccessListener(new OnSuccessListener<FileDownloadTask.TaskSnapshot>() {
@Override
public void onSuccess(FileDownloadTask.TaskSnapshot taskSnapshot) {
Log.d(TAG, "download:SUCCESS");
// Send success broadcast with number of bytes downloaded
broadcastDownloadFinished(downloadPath, taskSnapshot.getTotalByteCount());
showDownloadFinishedNotification(downloadPath, (int) taskSnapshot.getTotalByteCount());
// Mark task completed
taskCompleted();
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
Log.w(TAG, "download:FAILURE", exception);
Log.w(TAG, "download:FAILURE", exception.getCause());
// Send failure broadcast
broadcastDownloadFinished(downloadPath, -1);
showDownloadFinishedNotification(downloadPath, -1);
// Mark task completed
taskCompleted();
}
});
我們可以使用上面代碼中說明的firebase customApp –