Search in sources :

Example 1 with StorageMetadata

use of com.google.firebase.storage.StorageMetadata in project Tapad by berict.

the class PresetStoreAdapter method onFirebasePresetUpdated.

private void onFirebasePresetUpdated(final String presetName, final Runnable onUpdated) {
    StorageReference metadataReference = FirebaseStorage.getInstance().getReferenceFromUrl("gs://tapad-4d342.appspot.com/presets/" + presetName).child("preset.zip");
    metadataReference.getMetadata().addOnSuccessListener(new OnSuccessListener<StorageMetadata>() {

        @Override
        public void onSuccess(StorageMetadata storageMetadata) {
            Log.d(TAG, "Successful getting metadata");
            if (storageMetadata.getUpdatedTimeMillis() > new File(PROJECT_LOCATION_PRESETS + "/" + presetName + "/about/json.txt").lastModified()) {
                // firebase preset is updated since last download
                // get the new updated preset
                Log.d(TAG, "Preset updated");
                onUpdated.run();
            } else {
                Log.d(TAG, "Preset not updated");
            }
        }
    }).addOnFailureListener(new OnFailureListener() {

        @Override
        public void onFailure(@NonNull Exception e) {
            Log.d(TAG, "Failed to get preset metadata");
        }
    });
}
Also used : StorageMetadata(com.google.firebase.storage.StorageMetadata) StorageReference(com.google.firebase.storage.StorageReference) OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) File(java.io.File) OnFailureListener(com.google.android.gms.tasks.OnFailureListener)

Example 2 with StorageMetadata

use of com.google.firebase.storage.StorageMetadata in project Tapad by berict.

the class FirebaseHelper method getStorageMetadata.

public StorageMetadata getStorageMetadata(StorageReference storageReference, Activity activity) {
    FirebaseApp.initializeApp(activity);
    final StorageMetadata[] mStorageMetadata = { null };
    storageReference.getMetadata().addOnSuccessListener(new OnSuccessListener<StorageMetadata>() {

        @Override
        public void onSuccess(StorageMetadata storageMetadata) {
            Log.d(TAG, "Successful getting metadata");
            mStorageMetadata[0] = storageMetadata;
        }
    }).addOnFailureListener(new OnFailureListener() {

        @Override
        public void onFailure(@NonNull Exception e) {
            Log.d(TAG, "Failed to get metadata");
        }
    });
    return mStorageMetadata[0];
}
Also used : StorageMetadata(com.google.firebase.storage.StorageMetadata) OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) OnFailureListener(com.google.android.gms.tasks.OnFailureListener)

Example 3 with StorageMetadata

use of com.google.firebase.storage.StorageMetadata in project Carebase by robertsimoes.

the class CarebaseDatabase method uploadProfilePhoto.

@Override
public void uploadProfilePhoto(String userId, Uri photo, OnSuccessListener callback) {
    StorageMetadata metadata = new StorageMetadata.Builder().setContentType("image/jpg").build();
    profilePhotoStorage.child(userId).putFile(photo, metadata).addOnSuccessListener(callback);
}
Also used : StorageMetadata(com.google.firebase.storage.StorageMetadata)

Example 4 with StorageMetadata

use of com.google.firebase.storage.StorageMetadata in project BORED by invent2017.

the class StoryUpload method uploadImage.

private void uploadImage(Uri file) {
    // String fileUri = file.toString();
    // File imageFile = new File(fileUri);
    StorageMetadata metadata = new StorageMetadata.Builder().setContentType("image/jpg").build();
    String imageFileName = file.getLastPathSegment();
    // TODO: check if image with same name already exists
    UploadTask uploadTask = mStorageRef.child(imageFileName).putFile(file, metadata);
    uploadTask.addOnFailureListener(new OnFailureListener() {

        @Override
        public void onFailure(@NonNull Exception e) {
            AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext());
            builder.setMessage("Upload failed. Please try again later.").setPositiveButton("OK", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    Intent i = new Intent(StoryUpload.this, MapsActivityCurrentPlace.class);
                    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(i);
                }
            });
            builder.create().show();
        }
    }).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {

        @Override
        public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
            uploadImageData(taskSnapshot);
        }
    });
}
Also used : StorageMetadata(com.google.firebase.storage.StorageMetadata) AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) Intent(android.content.Intent) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) UploadTask(com.google.firebase.storage.UploadTask) NonNull(android.support.annotation.NonNull) OnFailureListener(com.google.android.gms.tasks.OnFailureListener)

Example 5 with StorageMetadata

use of com.google.firebase.storage.StorageMetadata in project Firebase-Helper by AtifAbbAsi19.

the class FireBaseHelper method uploadAudio.

public void uploadAudio(Uri uri, StorageReference filePath, FirebaseUrlCallInterface urlAudioCallInterface) {
    this.firebaseAudioUrlCallInterface = urlAudioCallInterface;
    progressDialog.setMessage(context.getString(R.string.loading));
    progressDialog.show();
    // Create file metadata including the content type
    StorageMetadata metadata = new StorageMetadata.Builder().setContentType("audio/mpeg").build();
    filePath = mFStorage.child("audio").child(getRandomId() + ".mp3");
    filePath.putFile(galleryUri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {

        @Override
        public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
            progressDialog.dismiss();
            String url = taskSnapshot.getDownloadUrl().toString();
            firebaseAudioUrlCallInterface.onFirebaseCallComplete(url);
        }
    }).addOnFailureListener(new OnFailureListener() {

        @Override
        public void onFailure(@NonNull Exception exception) {
            progressDialog.dismiss();
            firebaseAudioUrlCallInterface.onFirebaseCallFailure(exception);
        // Toast.makeText(getApplicationContext(), exception.getMessage(), Toast.LENGTH_LONG).show();
        }
    }).addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {

        @Override
        public void onProgress(UploadTask.TaskSnapshot taskSnapshot) {
            // displaying the upload progress
            double progress = (100.0 * taskSnapshot.getBytesTransferred()) / taskSnapshot.getTotalByteCount();
            progressDialog.setMessage("Uploaded " + ((int) progress) + "%...");
        }
    });
}
Also used : StorageMetadata(com.google.firebase.storage.StorageMetadata) UploadTask(com.google.firebase.storage.UploadTask) NonNull(android.support.annotation.NonNull) OnFailureListener(com.google.android.gms.tasks.OnFailureListener) FirebaseAuthUserCollisionException(com.google.firebase.auth.FirebaseAuthUserCollisionException)

Aggregations

StorageMetadata (com.google.firebase.storage.StorageMetadata)7 OnFailureListener (com.google.android.gms.tasks.OnFailureListener)6 NonNull (android.support.annotation.NonNull)3 OnSuccessListener (com.google.android.gms.tasks.OnSuccessListener)3 UploadTask (com.google.firebase.storage.UploadTask)3 DialogInterface (android.content.DialogInterface)2 Intent (android.content.Intent)2 AlertDialog (android.support.v7.app.AlertDialog)2 StorageReference (com.google.firebase.storage.StorageReference)2 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 FirebaseAuthUserCollisionException (com.google.firebase.auth.FirebaseAuthUserCollisionException)1