Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.02 firebase storage put file #19

Open
wants to merge 9 commits into
base: 1.00-starting-point
Choose a base branch
from

Conversation

ijann
Copy link

@ijann ijann commented Jun 14, 2017

Hello, I'm sorry but I have a problem, I do not upload the photo to my store, the rules in my firebase store console is:

service firebase.storage {
match /b/chatfriendly.appspot.com/o {
match /chat_photos/{allPaths=**} {
allow read, write: if request.auth != null && request.resource.size < 3 * 1024 * 1024;
}
}
}


And the rule in the firebase database is:

{
"rules": {
"messages": {
// only authenticated users can read and write the messages node
".read": "auth != null",
".write": "auth != null",
"$id": {
// the read and write rules cascade to the individual messages
// messages should have a 'name' and 'text' key or a 'name' and 'photoUrl' key
".validate": "newData.hasChildren(['name', 'text']) && !newData.hasChildren(['photoUrl']) || newData.hasChildren(['name', 'photoUrl']) && !newData.hasChildren(['text'])"
}
}
}
}

For authentication use the new method:

startActivityForResult(
AuthUI.getInstance()
.createSignInIntentBuilder()
.setIsSmartLockEnabled(false)
.setProviders(Arrays.asList(
new AuthUI.IdpConfig.Builder(AuthUI.EMAIL_PROVIDER).build(),
new AuthUI.IdpConfig.Builder(AuthUI.GOOGLE_PROVIDER).build()))
.build(), RC_SIGN_IN);

I do not know if it's the wrong extensions

build.gradle (app)

dependency {

compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.github.bumptech.glide:glide:4.0.0-RC0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.0.0-RC0'
//  Single target that includes all FirebaseUI libraries above
compile 'com.firebaseui:firebase-ui:1.2.0'

//  Firebase database, Storage y Authentication
compile 'com.google.firebase:firebase-database:10.2.6'
compile 'com.google.firebase:firebase-storage:10.2.6'
compile 'com.google.firebase:firebase-auth:10.2.6'

//  Login with google-play-service
compile 'com.google.android.gms:play-services-auth:10.2.6'

}
apply plugin: 'com.google.gms.google-services'

build.gradle (project)

buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.google.gms:google-services:3.1.0'
}
}

Well the most important method for the upload is:

`@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == RC_SIGN_IN) {
        if (resultCode == RESULT_OK)
            Toast.makeText(this, "Signed In!", Toast.LENGTH_SHORT).show();
        else if (resultCode == RESULT_CANCELED) {
            Toast.makeText(this, "Sign in canceled", Toast.LENGTH_SHORT).show();
            finish();
        } else if (requestCode == RC_PHOTO_PICKER && resultCode == RESULT_OK) {

            Uri selectedImageUri = data.getData();
            StorageReference photoRef =
                    mChatFotosStorageReference.child(selectedImageUri.getLastPathSegment());

            photoRef.putFile(selectedImageUri).addOnSuccessListener(
                    this,
                    new OnSuccessListener<UploadTask.TaskSnapshot>() {
                @Override
                public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                    @SuppressWarnings("VisibleForTests")
                    Uri downloadUrl = taskSnapshot.getDownloadUrl();
                    FriendlyMessage friendlyMessage = new FriendlyMessage(
                            null, mUsername, downloadUrl.toString());
                    mMessageDatabaseReference.push().setValue(friendlyMessage);
                }
            });

        }
    }
}`

I give it to upload a photo, I select the photo and nothing
06-14 19:24:24.100 7781-17645/com.example.chatfriendly V/FA: Using measurement service 06-14 19:24:24.100 7781-17645/com.example.chatfriendly V/FA: Connection attempt already in progress 06-14 19:24:24.101 7781-17645/com.example.chatfriendly D/FA: Connected to remote service 06-14 19:24:24.102 7781-17645/com.example.chatfriendly V/FA: Processing queued up service tasks: 2 06-14 19:24:24.160 7781-7781/com.example.chatfriendly W/IInputConnectionWrapper: reportFullscreenMode on inexistent InputConnection 06-14 19:24:24.160 7781-7781/com.example.chatfriendly W/IInputConnectionWrapper: finishComposingText on inactive InputConnection 06-14 19:24:29.498 7781-17645/com.example.chatfriendly V/FA: Inactivity, disconnecting from the service 06-14 19:24:30.114 7781-17645/com.example.chatfriendly V/FA: Using measurement service 06-14 19:24:30.114 7781-17645/com.example.chatfriendly V/FA: Connecting to remote service 06-14 19:24:30.117 7781-17645/com.example.chatfriendly V/FA: Activity resumed, time: 20019705 06-14 19:24:30.206 7781-7869/com.example.chatfriendly E/EGL_emulation: tid 7869: eglSurfaceAttrib(1178): error 0x3009 (EGL_BAD_MATCH) 06-14 19:24:30.206 7781-7869/com.example.chatfriendly W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x8a15d340, error=EGL_BAD_MATCH 06-14 19:24:30.299 7781-17645/com.example.chatfriendly D/FA: Connected to remote service 06-14 19:24:30.300 7781-17645/com.example.chatwithfriendly V/FA: Processing queued up service tasks: 1 06-14 19:24:35.301 7781-17645/com.example.chatfriendly V/FA: Inactivity, disconnecting from the service

@ijann
Copy link
Author

ijann commented Jun 15, 2017

I changed Glide by Picasso, I thought that version 4 of Glide produced me problems but this same, I do not upload the image, some idea please

@KRashEk
Copy link

KRashEk commented Feb 12, 2019

Uri downloadUrl = taskSnapshot.getDownloadUrl(); this api not found in new version. so you have to modified code from photoref.putfile following snippet is working in latest firebase config

			Uri selectedImageUri = data.getData();

			// Get a reference to store file at chat_photos/<FILENAME>
			final StorageReference photoRef = mChatPhotoStorageReference.child(selectedImageUri.getLastPathSegment());
			photoRef.putFile(selectedImageUri).continueWithTask(new Continuation<UploadTask.TaskSnapshot, Task<Uri>>() {
				@Override
				public Task<Uri>then(@NonNull Task<UploadTask.TaskSnapshot> task) throws Exception {
					if (!task.isSuccessful()) {
						throw task.getException();
					}
					return photoRef.getDownloadUrl();
				}
			}).addOnCompleteListener(new OnCompleteListener<Uri>() {
				@Override
				public void onComplete(@NonNull Task<Uri> task) {
					if (task.isSuccessful()) {
						Uri downloadurl = task.getResult();
                        FriendlyMessage friendlyMessage =
                                new FriendlyMessage(null, mUsername, downloadurl.toString());
                        mMessageDatabaseReference.push().setValue(friendlyMessage);
					}
				}
			});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.