Reputation: 1251
customApp= new FirebaseApp(getApplicationContext(),"My News",<to be filled>);
storage = FirebaseStorage.getInstance(customApp);
I'm new to firebase and what is the exact use of the custom App.
I want to create a custom app to upload large files to google cloud storage using firebase. is that custom app recommended for me?
Upvotes: 0
Views: 149
Reputation: 1251
Great answer Mr. Frank van Puffelen. It's working for me (imported bucket from Google Cloud Storage.)
mStorageRef = FirebaseStorage.getInstance("gs://c......s").getReference();
Download the file from google cloud storage to a local device using firebase.
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();
}
});
Upvotes: 0
Reputation: 599101
If you're new to Firebase, chances are you don't need a custom FirebaseApp
. Instead, just use FirebaseStorage.getInstance().getReference()
as shown in the Firebase Storage documentation.
Upvotes: 0
Reputation: 1251
No need to use customApp;
Simply we can use
storage = FirebaseStorage.getInstance("gs://<Google cloud storage bucket name>");
If we want storage references then
mStorageRef = storage.getReferenceFromUrl("gs://<Google cloud storage bucket name>");
Upvotes: 1
Reputation: 1251
@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`
}
Upvotes: 0