# getBase64FromImage returning blank spaces

**URL:** <https://forums.fusetools.com/t/getbase64fromimage-returning-blank-spaces/555>\
**Category:** Bug Reports\
**Created:** [October 3, 2016, 1:14pm UTC](https://forums.fusetools.com/t/getbase64fromimage-returning-blank-spaces/555 "2016-10-03T13:14:48Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![zaulin](https://avatars.discourse-cdn.com/v4/letter/z/d26b3c/32.png) [@zaulin](https://forums.fusetools.com/u/zaulin)\
**Post date:** [October 3, 2016, 1:14pm UTC](https://forums.fusetools.com/t/getbase64fromimage-returning-blank-spaces/555/1 "2016-10-03T13:14:48Z")

</div>

Hi,

after having some issues with getBase64FromImage i decided to send to my mail the result and i got an string with some blank spaces on it (if i’m not wrong that should not be allowed in a base64 string). I guess that’s a bug.

testing on a Nexus 7. Fuse 0.26

```
     cameraRoll.getImage()
        .then(function(image) {                
            ImageTools.getBase64FromImage(image).then(function(ImageBase){
                email.compose("myEmail", "", "", "subject", ImageBase);
            })
        }, function(error) {
            // Will be called if the user aborted the selection or if an error occurred.
        });
```

---

<div class="post-metadata">

**Author:** ![Andreas\_Ronning](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/andreas_ronning/32/303_2.png) [@Andreas\_Ronning](https://forums.fusetools.com/u/Andreas_Ronning)\
**Post date:** [October 3, 2016, 8:51pm UTC](https://forums.fusetools.com/t/getbase64fromimage-returning-blank-spaces/555/2 "2016-10-03T20:51:28Z")

</div>

Hey! For fun, if you still have that email, did it actually look like a base64 string with some erroneous spaces in it or did it just look like some garbage? The B64 encoding on Android is handled through the `android.util.Base64` class so this is likely me having configured it wrong somehow. Curious to see the string you got though.

---

<div class="post-metadata">

**Author:** ![zaulin](https://avatars.discourse-cdn.com/v4/letter/z/d26b3c/32.png) [@zaulin](https://forums.fusetools.com/u/zaulin)\
**Post date:** [October 3, 2016, 8:54pm UTC](https://forums.fusetools.com/t/getbase64fromimage-returning-blank-spaces/555/3 "2016-10-03T20:54:44Z")

</div>

It looks as a base64 string with spaces in it. How do u want me to share it with u? 🙂

---

<div class="post-metadata">

**Author:** ![zaulin](https://avatars.discourse-cdn.com/v4/letter/z/d26b3c/32.png) [@zaulin](https://forums.fusetools.com/u/zaulin)\
**Post date:** [October 3, 2016, 9:04pm UTC](https://forums.fusetools.com/t/getbase64fromimage-returning-blank-spaces/555/4 "2016-10-03T21:04:17Z")

</div>

here u have it:

> <https://gist.github.com/zaulin/0a04652d3a6a5e1aa250dc9e4eb10c62>

---

<div class="post-metadata">

**Author:** ![kusma](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/kusma/32/595_2.png) [@kusma](https://forums.fusetools.com/u/kusma)\
**Post date:** [October 3, 2016, 9:35pm UTC](https://forums.fusetools.com/t/getbase64fromimage-returning-blank-spaces/555/5 "2016-10-03T21:35:28Z")

</div>

E-mail messages [doesn’t support very long lines](https://tools.ietf.org/html/rfc2822#section-2.1.1) without additional encoding, so it’s likely that the spaces are required to avoid breaking the email-transport.

---

<div class="post-metadata">

**Author:** ![zaulin](https://avatars.discourse-cdn.com/v4/letter/z/d26b3c/32.png) [@zaulin](https://forums.fusetools.com/u/zaulin)\
**Post date:** [October 3, 2016, 9:38pm UTC](https://forums.fusetools.com/t/getbase64fromimage-returning-blank-spaces/555/6 "2016-10-03T21:38:18Z")

</div>

if i show something like: imgStr.substring(0,50) i see the blank spaces if i URIEncode the result and send it to the email there are blank spaces encoded

---

<div class="post-metadata">

**Author:** ![zaulin](https://avatars.discourse-cdn.com/v4/letter/z/d26b3c/32.png) [@zaulin](https://forums.fusetools.com/u/zaulin)\
**Post date:** [October 4, 2016, 11:26am UTC](https://forums.fusetools.com/t/getbase64fromimage-returning-blank-spaces/555/7 "2016-10-04T11:26:29Z")

</div>

btw: in the email i get carriage returns but those are not in the original base64 string

---

<div class="post-metadata">

**Author:** ![zaulin](https://avatars.discourse-cdn.com/v4/letter/z/d26b3c/32.png) [@zaulin](https://forums.fusetools.com/u/zaulin)\
**Post date:** [October 6, 2016, 10:47pm UTC](https://forums.fusetools.com/t/getbase64fromimage-returning-blank-spaces/555/8 "2016-10-06T22:47:32Z")

</div>

Hi,

after updating to 0.27 it’s working on Android (great!!) but NOT on iOS 🙂

I tried an example with a very small image (to avoid having problems with text formating)

what i got was:

Android (correct base64 image):

iVBORw0KGgoAAAANSUhEUgAAAAQAAAAECAIAAAAmkwkpAAAAA3NCSVQICAjb4U/gAAAAJUlEQVQImWP8//8/AwOD8DkPBgYGJgYkwCjkc5aBgeHXdjN0GQAHiQc/5ZA9fQAAAABJRU5ErkJggg==

iPhone (non valid base64 image):

/9j/4AAQSkZJRgABAQAASABIAAD/4QBYRXhpZgAATU0AKgAAAA3D47HZVh6IWpCMpzIRpyIKUopyIKTi3KUm22222223c//9k=

i tried both with this online converter:

> **[Best Online Base64 to Image converter](https://codebeautify.org/base64-to-image-converter)**
>
> Converts base64 string into image and download

---

<div class="post-metadata">

**Author:** ![Andreas\_Ronning](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/andreas_ronning/32/303_2.png) [@Andreas\_Ronning](https://forums.fusetools.com/u/Andreas_Ronning)\
**Post date:** [October 7, 2016, 6:20pm UTC](https://forums.fusetools.com/t/getbase64fromimage-returning-blank-spaces/555/9 "2016-10-07T18:20:50Z")

</div>

Hmmm thanks for that extra info. So looking at our code now what seems to be going wrong is that the image representation returned on iOS is actually a jpg and on android it’s a png. This is clearly wrong, as it should be either the same on both or allow you to choose, so that’s going into an issue.

This would explain why the Base64 comes out different. I’ll write up some tests so the returned data is identical.

Thanks for reporting in detail
