Firebase photoURL is not displaying properly in react-native - android

I'm using the Firebase authentication module in react-native with native-cli. On sign up, I'm uploading an image using react-native-document-picker. After selecting an image from the gallery it will look like this:
{
"fileCopyUri":"content://com.android.providers.media.documents/document/image%3A33077",
"name":"IMG-20211005-WA0007.jpg",
"size":67094,
"type":"image/jpeg",
"uri":"content://com.android.providers.media.documents/document/image%3A33077"
}
and using this function to upload it on firebase:
auth().currentUser.updateProfile({
displayName:fullname,
photoURL:JSON.stringify(pic),
})
now when I get it like this:
const fireUser = auth().currentUser;
console.log(JSON.parse(fireUser.photoURL))
It displays the image on the screen but when I quit the app and again open or log in to the app it's not displaying the image but I'm having pic in photoURL.
Is it possible to convert file?
{
"fileCopyUri":"content://com.android.providers.media.documents/document/image%3A33077",
"name":"IMG-20211005-WA0007.jpg",
"size":67094,
"type":"image/jpeg",
"uri":"content://com.android.providers.media.documents/document/image%3A33077"
}
into URL?
What am I doing wrong?

The URL you're passing to updateProfile is a local URL on your Android device, which won't work. To ensure the profile is visible, upload the local file to a public place in the cloud, and then pass the URL for that location to updateProfile.
For example, you can upload the file to Cloud Storage with Firebase, then get the download URL that provides read-only, public access to it, and store that in the user profile.

Related

Android - how to create file object from Imageview image

Im making and android app which let the user select an image from the phone and load it to an ImageView. The further process is to send the image as a POST request to a PHP script
It all works fine if I load the image to a File object from the file location, but this require that the user open a setting on the phone which allow the app to access and manage local files..
So, is there a way to read the image from the imagview into a File object?
This is my current working code
val fil = File(getRealPathFromURI(imageUri!!).toString())
if (Build.VERSION.SDK_INT >= 30){
if (!Environment.isExternalStorageManager()){
var getpermission = Intent()
getpermission.setAction(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION);
startActivity(getpermission);
}
}
var reqB = RequestBody.create("image/*".toMediaTypeOrNull(),fil)
var part = MultipartBody.Part.createFormData("file",fil.name,reqB)
Kotlin throws an access error if I try to load it to a File object if the users dont allow it through the settings on the phone. I believe its a security issue on android.
Really what I want to do is
Let the user select an existing image on the phone
Display it in an imageview
Create a function which get the selected image into an MultipartBody.part without the user having to grant the app access to special rights

While adding same image 2 times from imageview firebase storage override previous and makes 2 different url for same image

I have make a ImageView to add images to firebase storage it works fine when I restart the activity but without restarting activity when I upload first image to firebase storage it add successfully but when I upload the same image another time it override previous image and generate new URL, both previous and new URL contains same image and image is only one in firebase storage for both URL the problem is when I delete image from any one URL it delete image and then second URL gets empty and it does not contain image.

Retrieve Android/Cloudinary uploaded image URL

Im using Cloudinary along with an Android App.
Im uploading a image using:
cloudinary.uploader().upload(imagePath, ObjectUtils.emptyMap());
The problem is that I need the url to retrieve this image later. Is there any method that I can use to store the uploaded image url inside my App?
Thanks!
According to their documentation
Documentaion
This code shows
Map uploadResult = cloudinary.uploader().upload(file, ObjectUtils.emptyMap());
Uploading is performed synchronously. Once finished, the uploaded image is immediately available for manipulation and delivery.
An upload API call returns a JSON object with content similar to that shown in the following example:
{
"public_id":"tquyfignx5bxcbsupr6a",
"version":1375302801,
"signature":"52ecf23eeb987b3b5a72fa4ade51b1c7a1426a97",
"width":1920,
"height":1200,
"format":"jpg",
"resource_type":"image",
"created_at":"2013-07-31T20:33:21Z",
"bytes":737633,
"type":"upload",
"url":
"http://res.cloudinary.com/demo/image/upload/v1375302801/tquyfignx5bxcbsupr6a.jpg",
"secure_url":
"https://res.cloudinary.com/demo/image/upload/v1375302801/tquyfignx5bxcbsupr6a.jpg",
"etag":"1adf8d2ad3954f6270d69860cb126b24"
}
The response is automatically parsed and converted into a Map.

How to open google drive public link

I have uploaded a file on google drive, i have made it public. i am able to access this on browser but not with my android app.
I need to access this public link on MY ANDROID APP.
PFB the link of file:
https://drive.google.com/file/d/0B56C1LC3IVXCV055WFIyVTZjTTA/edit?usp=docslist_api
Is this possible to access a publicly shared GD file on android app?
Code snippet is
URL url = new URL("https://drive.google.com/file/d/0B56C1LC3IVXCV055WFIyVTZjTTA/edit?usp=docslist_api");
Bitmap bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream());
return bmp;
The solution is to format the address of the document you have shared.
Check this :
URL = "https://docs.google.com/uc?id=" + IDFile + "&export=download";
Your link is not to image but to Google Drive App with this image opened, real URL to image is this
Consider using Google Drive API
How about scaling the picture down to a reasonable size, it may just be that the image is too large for your heap to load
Bitmap.createScaledBitmap(Bitmap src, int Width, int Height, boolean filter)
There one other way to access file's public link By adding :
https://googledrive.com/host/[folderId]/fileName.extension
As you have provide file url
You can use that url like this for public access
https://googledrive.com/host/0B56C1LC3IVXCV055WFIyVTZjTTA
You simply need to grab the webContentLink of the newly created file.
From the documentation ...
webContentLink string
A link for downloading the content of the file in a browser using cookie based authentication. In cases where the content is shared publicly, the content can be downloaded without any credentials.

Unable to fetch GPlus profile pic. Is the Google Plus Image fetch URL updated?

It's weird, but till yesterday i was able to get the gplus user's image in my app but today it's just not coming. Nothing simply blank. And just appears at some time..
I have been using the urls specified in Getting Google+ profile picture url with user_id but these all seem invalid and gives 404 Error.
https://plus.google.com/s2/photos/profile/116018066779980863044?sz=100
If anybody could help me out why this weird behaviour. The Profile pic appears seldom. But mostly it's blank.
The image URL you were using was never a public API and so there was no guarantee it would continue to work. The recommended practice going forward is to use the people.get API method to get the profile => image => url value instead. That URL could stop working if the user changes their avatar so you might want to fetch the actual image and cache it on your own servers.
I think the Image url has been updated.
Inorder to get that, we can use the PlusClient objects methods:
imageURL = mPlusClient.getCurrentPerson().getImage().getUrl()
{Returns a String - Image Url as String}
imageURL = mPlusClient.getCurrentPerson().getImage()
{Returns an instance of Image object}

Categories

Resources