Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I need to add jpeg images to firestore db records. My preferred way would be in a Blob as I have used in Sqlite records. I have run into some problems in trying this. The following is my best try so far:

public Blob getImage() {
    Uri uri = Uri.fromFile(new 
File(mCurrentPhotoPath));
    File f1 = new File(mCurrentPhotoPath);
    URL myURL = null;
    try {

        myURL = f1.toURI().toURL();
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }

    Bitmap bitmap = null;

    BitmapFactory.Options options = new 
BitmapFactory.Options();
    options.inPreferredConfig = 
Bitmap.Config.ARGB_8888;
    try {
        if (myURL != null) {
            bitmap = 
BitmapFactory.decodeStream( 
myURL.openConnection().getInputStream());
            String wBlob = 
encodeToBase64(bitmap,
 Bitmap.CompressFormat.JPEG, 100);
       blob = fromBase64String(wBlob);           
}


    } catch (java.io.IOException e) {
        e.printStackTrace();

    }
    return blob;
}

My problem is in the
blob = fromBase64String(wBlob);

I also have a problem with passing a blob to the class that sets the record. intent.putExtra("blobImage", blob ); I appreciate any help.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
101 views
Welcome To Ask or Share your Answers For Others

1 Answer

Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...