Java Code Examples for com.google.firebase.storage.StorageReference#putFile()
The following examples show how to use
com.google.firebase.storage.StorageReference#putFile() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainActivity.java From Shipr-Community-Android with GNU General Public License v3.0 | 6 votes |
private void uploadImageToStorage(StorageReference photoRef, Uri selectedImageUri) { UploadTask uploadTask = photoRef.putFile(selectedImageUri); Task<Uri> urlTask = uploadTask.continueWithTask(task -> { if (!task.isSuccessful()) { throw Objects.requireNonNull(task.getException()); } // Continue with the task to get the download URL return photoRef.getDownloadUrl(); }).addOnCompleteListener(task -> { if (task.isSuccessful()) { downloadUri = task.getResult(); updateProfilePic(downloadUri); } // Handle failures // ... }); }
Example 2
Source File: DatabaseHelper.java From social-app-android with Apache License 2.0 | 5 votes |
public UploadTask uploadImage(Uri uri, String imageTitle) { StorageReference riversRef = getStorageReference().child(IMAGES_STORAGE_KEY + "/" + imageTitle); // Create file metadata including the content type StorageMetadata metadata = new StorageMetadata.Builder() .setCacheControl("max-age=7776000, Expires=7776000, public, must-revalidate") .build(); return riversRef.putFile(uri, metadata); }
Example 3
Source File: DatabaseHelper.java From social-app-android with Apache License 2.0 | 5 votes |
public UploadTask uploadImage(Uri uri, String imageTitle) { StorageReference riversRef = getStorageReference().child(IMAGES_STORAGE_KEY + "/" + imageTitle); // Create file metadata including the content type StorageMetadata metadata = new StorageMetadata.Builder() .setCacheControl("max-age=7776000, Expires=7776000, public, must-revalidate") .build(); return riversRef.putFile(uri, metadata); }
Example 4
Source File: UploadProcessor.java From gdx-fireapp with Apache License 2.0 | 4 votes |
void processUpload(final FirebaseStorage firebaseStorage, final String path, final FileHandle file, final FuturePromise<FileMetadata> promise) { StorageReference dataRef = firebaseStorage.getReference().child(path); UploadTask uploadTask = dataRef.putFile(Uri.fromFile(file.file())); processUpload(firebaseStorage, uploadTask, promise); }
Example 5
Source File: MainActivity.java From stockita-point-of-sale with MIT License | 4 votes |
/** * Helper method to save and upload images to the server */ private void saveImageIntoRealDatabaseAndStorage(String realFilePath) { /** * Add the {@link ItemImageModel} to the server */ // Instantiate the model pass file path and push key as argument ItemImageModel itemImageModel = new ItemImageModel(realFilePath, aaItemMasterPushKey); // Initialize the server location for real time database DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference() .child(aaItemMasterUserUid) .child(Constants.FIREBASE_ITEM_MASTER_IMAGE_LOCATION) .child(aaItemMasterPushKey); // Set the value with push() so each itemMaster can have multiple itemImage databaseReference.push().setValue(itemImageModel); /** * Now upload the file to the cloud */ // Initialize storage mImageStorageRef = FirebaseStorage.getInstance().getReference(); // Get reference to the specific storage location to storage the images StorageReference imageStorageRefForUser = mImageStorageRef .child(aaItemMasterUserUid) .child(Constants.FIREBASE_ITEM_MASTER_IMAGE_LOCATION) .child(aaItemMasterPushKey); // Get the imagePath from the model then convert imagePath to Uri Uri file = Uri.fromFile(new File(itemImageModel.getImageUrl())); // Pack the Uri object into StorageReference object StorageReference uriRef = imageStorageRefForUser.child(file.getLastPathSegment()); // Create & add file metadata including the content type StorageMetadata metadata = new StorageMetadata.Builder() .setContentType("image/jpg") .build(); // Upload the file, pass the Uri file and the metadata as argument UploadTask uploadTask = uriRef.putFile(file, metadata); // Register observers to listen for when the upload is done or if it fails uploadTask.addOnFailureListener(this, new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) { } }).addOnSuccessListener(this, new OnSuccessListener<UploadTask.TaskSnapshot>() { @Override public void onSuccess(@NonNull UploadTask.TaskSnapshot taskSnapshot) { //Uri downloadUrl = taskSnapshot.getDownloadUrl(); } }); }