Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-25766] Android: Ti.Utils.base64encode for cannot encode (Image) Ti.Blob anymore. Result = null

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2018-02-09T19:53:54.000+0000
Affected Version/sRelease 7.0.2
Fix Version/sRelease 7.0.2
ComponentsAndroid
Labelsregression
ReporterMuhammad Ahmed Fahad
AssigneeHans Knöchel
Created2018-02-09T09:00:47.000+0000
Updated2018-02-12T02:25:16.000+0000

Description

Ti SDK: 7.0.2.v20180207091331 Device: Samsung Galaxy S8+ Android: 7.0.0 Works fine with Ti SDK 7.0.1.GA Test Case:
  Ti.Media.showCamera({
    success:function(event) {
      if(event.mediaType === Ti.Media.MEDIA_TYPE_PHOTO) {
        var image = event.media;

        Ti.API.info(Ti.Utils.base64encode(image).text);
      }
    },
    cancel:function() {
    },
    error:function(err) {
      Ti.API.error(err);
    },
    mediaTypes:[Ti.Media.MEDIA_TYPE_PHOTO]
  });
Expect Output: A random encoded string Actual output: Uncaught TypeError: Cannot read property 'text' of null

Comments

  1. Muhammad Ahmed Fahad 2018-02-09

    Please try to fix this issue before releasing 7.0.2
  2. Ewan Harris 2018-02-09

    [~fahad86] Thanks for the ticket, I'll move this across to TIMOB Able to reproduce this issue using SDK: 7.0.2.v20180207091331 One Plus 3 7.1.1 This does not occur using SDK 7.0.2.v20180207022213 so the cause appears to be TIMOB-25727 Full code include permissions handling
       var win = Ti.UI.createWindow();
       win.open();
       
       function takePhoto() {
           Ti.Media.showCamera({
               mediaTypes: [Ti.Media.MEDIA_TYPE_PHOTO],
               success: function(event) {
                   console.log(event);
                   if(event.mediaType === Ti.Media.MEDIA_TYPE_PHOTO) {
                       var image = event.media;
                       Ti.API.info(Ti.Utils.base64encode(image))
                       Ti.API.info(Ti.Utils.base64encode(image).text);
                   }
               },
               error: function(e) {
               },
               cancel: function(e) {
               }
           });
       }
       
       
       win.addEventListener('click', () => {
           var hasCameraPermissions = Ti.Media.hasCameraPermissions();
       
           if (hasCameraPermissions) {
               takePhoto();
           }
       
           Ti.Media.requestCameraPermissions(function(e) {
               takePhoto();
           });
       });
       

    Steps to reproduce

    Build to Android

    Tap screen

    Take photo

    Actual

    Code throws error
       [INFO]  {"y":0,"x":0,"width":2610,"height":4640,"media":{"height":4640,"type":1,"mimeType":"image/jpeg","text":null,"nativePath":"file:///data/user/0/com.appc.test/app_appdata/tia1518182936027.jpg","width":2610,"length":1720147,"file":{"writable":true,"executable":false,"nativePath":"file:///data/user/0/com.appc.test/app_appdata/tia1518182936027.jpg","name":"tia1518182936027.jpg","symbolicLink":false,"size":1720147,"directoryListing":[],"hidden":false,"readonly":false,"parent":{"writable":true,"executable":false,"nativePath":"file:///data/user/0/com.appc.test/app_appdata","name":"app_appdata","symbolicLink":false,"size":4096,"directoryListing":["tia1518182119535.jpg","tia1518182257927.jpg","tia1518182339714.jpg","tia1518182791965.jpg","tia1518182936027.jpg"],"hidden":false,"readonly":false,"parent":{"writable":true,"executable":false,"nativePath":"file:///data/user/0/com.appc.test","name":"com.appc.test","symbolicLink":false,"size":4096,"directoryListing":["cache","files","databases","shared_prefs","no_backup","app_appdata","code_cache"],"hidden":false,"readonly":false,"parent":{"writable":false,"executable":false,"nativePath":"file:///data/user/0","name":"0","symbolicLink":false,"size":12288,"directoryListing":[],"hidden":false,"readonly":false,"parent":{"writable":false,"executable":false,"nativePath":"file:///data/user","name":"user","symbolicLink":false,"size":4096,"directoryListing":[],"hidden":false,"readonly":false,"parent":{"writable":false,"executable":false,"nativePath":"file:///data","name":"data","symbolicLink":false,"size":4096,"directoryListing":[],"hidden":false,"readonly":false,"parent":{"writable":false,"executable":false,"nativePath":"file:///","name":"","symbolicLink":false,"size":1360,"directoryListing":[],"hidden":false,"readonly":false,"parent":null,"apiName":"Ti.Proxy","bubbleParent":true},"apiName":"Ti.Proxy","bubbleParent":true},"apiName":"Ti.Proxy","bubbleParent":true},"apiName":"Ti.Proxy","bubbleParent":true},"apiName":"Ti.Proxy","bubbleParent":true},"apiName":"Ti.Proxy","bubbleParent":true},"apiName":"Ti.Proxy","bubbleParent":true},"apiName":"Ti.Blob","bubbleParent":true},"mediaType":"public.image","code":0,"cropRect":{"height":4640,"width":2610,"y":0,"x":0},"success":true}
       [INFO]  null
       [ERROR] TiExceptionHandler: (main) [4238,4238] ----- Titanium Javascript Runtime Error -----
       [ERROR] TiExceptionHandler: (main) [0,4238] - In /app.js:1,317
       [ERROR] TiExceptionHandler: (main) [0,4238] - Message: Uncaught TypeError: Cannot read property 'text' of null
       [ERROR] TiExceptionHandler: (main) [0,4238] - Source: var win=Ti.UI.createWindow();win.open();function takePhoto(){Ti.Media.showCamera({mediaTypes:[Ti.Media.MEDIA_TYPE_PHOTO],success:function(event){if(console.log(event),event.mediaType===Ti.Media.MEDIA_TYPE_PHOTO){var image=event.media;Ti.API.info(Ti.Utils.base64encode(image)),Ti.API.info(Ti.Utils.base64encode(image).text)}},error:function(e){},cancel:function(e){}})}win.addEventListener('click',()=>{var hasCameraPermissions=Ti.Media.hasCameraPermissions();hasCameraPermissions&&takePhoto(),Ti.Media.requestCameraPermissions(function(e){takePhoto()})});
       

    Expected

    Logging like the below
       [INFO]  {"y":0,"x":0,"width":2610,"height":4640,"media":{"height":4640,"type":1,"mimeType":"image/jpeg","text":null,"nativePath":"file:///data/user/0/com.appc.test/app_appdata/tia1518182339714.jpg","width":2610,"length":1668017,"file":{"writable":true,"executable":false,"nativePath":"file:///data/user/0/com.appc.test/app_appdata/tia1518182339714.jpg","name":"tia1518182339714.jpg","symbolicLink":false,"size":1668017,"directoryListing":[],"hidden":false,"readonly":false,"parent":{"writable":true,"executable":false,"nativePath":"file:///data/user/0/com.appc.test/app_appdata","name":"app_appdata","symbolicLink":false,"size":4096,"directoryListing":["tia1518182119535.jpg","tia1518182257927.jpg","tia1518182339714.jpg"],"hidden":false,"readonly":false,"parent":{"writable":true,"executable":false,"nativePath":"file:///data/user/0/com.appc.test","name":"com.appc.test","symbolicLink":false,"size":4096,"directoryListing":["cache","files","databases","shared_prefs","no_backup","app_appdata","code_cache"],"hidden":false,"readonly":false,"parent":{"writable":false,"executable":false,"nativePath":"file:///data/user/0","name":"0","symbolicLink":false,"size":12288,"directoryListing":[],"hidden":false,"readonly":false,"parent":{"writable":false,"executable":false,"nativePath":"file:///data/user","name":"user","symbolicLink":false,"size":4096,"directoryListing":[],"hidden":false,"readonly":false,"parent":{"writable":false,"executable":false,"nativePath":"file:///data","name":"data","symbolicLink":false,"size":4096,"directoryListing":[],"hidden":false,"readonly":false,"parent":{"writable":false,"executable":false,"nativePath":"file:///","name":"","symbolicLink":false,"size":1360,"directoryListing":[],"hidden":false,"readonly":false,"parent":null,"apiName":"Ti.Proxy","bubbleParent":true},"apiName":"Ti.Proxy","bubbleParent":true},"apiName":"Ti.Proxy","bubbleParent":true},"apiName":"Ti.Proxy","bubbleParent":true},"apiName":"Ti.Proxy","bubbleParent":true},"apiName":"Ti.Proxy","bubbleParent":true},"apiName":"Ti.Proxy","bubbleParent":true},"apiName":"Ti.Blob","bubbleParent":true},"mediaType":"public.image","code":0,"cropRect":{"height":4640,"width":2610,"y":0,"x":0},"success":true}
       [INFO]  /9j/4QgHRXhpZgAATU0AKgAAAAgACgEPAAIAAAAIAAAAhgEQAAIAAAAOAAAAjgEaAAUAAAABAAAAnAEbAAUAAAABAAAApAEoAAMAAAABAAIAAAExAAIAAAAoAAAArAEyAAIAAAAUAAAA1AITAAMAAAABAAEAAIdpAAQAAAABAAAA6IglAAQAAAABAAAC5gAAAwBPbmVQbHVzAE9ORVBMVVMgQTMwMDMAAAAASAAAAAEAAABIAAAAAU9uZVBsdXMzLXVzZXIgNy4xLjEgTk1GMjZGIDExNCBkZXYta2V5cwAyMDE4OjAyOjA5IDEzOjE4OjU4AAAdgpoABQAAAAEAAAJKgp0ABQAAAAEAAAJSiCIAAwAAAAEAAAAAiCcAAwAAAAEZAAAAkAAABwAAAAQwMjIwkAMAAgAAABQAAAJakAQAAgAA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TpDREVGR0hJSlNUVVZXWFlaY2RlZmdoaWpzdHV2d3h5eoOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4eLj5OXm5+jp6vHy8/T19vf4+foBAAMBAQEBAQEBAQEAAAAAAAABAgMEBQYHCAkKCxEAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwDwOiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACikpaACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKSloAKKKKACiiigAooooASloooAKKKKACiiigAooooAKKKKACkpaKACiikoAWiiigAooooAKKSloAKKSloAKKKKACiiigAoopKAFooooAKKKKACiiigAopKWgAooooAKKKKACiiigAooooAKKKKACiiigApKWigAooooAKKKSgBaKKKACiiigAooooAKKKKACiiigAooooAKSlpKAFooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACilpKACilpKACiiigAooooAKKKKACiiigAoopaAEooooAKKKWgAooooASloooASiiigAooooAKKKKACiiigApaKKACiiigA7UUUUAFFFFABRRRQAlFFFABRRRQAUtJRQAUtFFABR2oooAKKKO1ABRRRQAUUUUDCiiigBO1FFFAgooooAKWkpaAEpaKKACiiigAooooAKKKKBi0UUUAFFFFAH//2f/k//9RdWFsY29tbSBDYW1lcmEgRGVidWcABQIAAgUAAgACAAAAUUNUVU4ABAAAAAkDAABRQ0FFQwBCEAAAEBETAO/0AADvdAEAAAAAAAAAAAC1ewEAEBETAACZDQAAEJYBDQIAAAEAAwAeAAgAAQCABzgEQCUAAPBA5hJiPqwTX+oAAPBA5hJg6gAA///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
       
  3. Hans Knöchel 2018-02-09

    master: https://github.com/appcelerator/titanium_mobile/pull/9813 7_0_X: https://github.com/appcelerator/titanium_mobile/pull/9812
  4. Joshua Quick 2018-02-09

    I see what was wrong. The issue was that the image blob's byte array was being transcoded from UTF-8 to UTF-16, which changed the binary before being base64 encoded. The old way of calling TiBlob.toBase64() would have preserved the original bytes.
  5. Lokesh Choudhary 2018-02-09

    FR Passed & verified the fix in SDK 7.0.2.v20180209105903. Studio Ver: 5.0.0.201712081732 SDK Ver: 7.0.2.v20180209105903 OS Ver: 10.13.2 Xcode Ver: Xcode 9.2 Appc NPM: 4.2.12-3 Appc CLI: 7.0.2-master.8 Daemon Ver: 1.0.1 Ti CLI Ver: 5.0.14 Alloy Ver: 1.11.0 Node Ver: 8.9.1 NPM Ver: 5.5.1 Java Ver: 1.8.0_101 Devices: ⇨ google Nexus 5 --- Android 6.0.1 ⇨ google Nexus 6P --- Android 7.1.2
  6. Lokesh Choudhary 2018-02-09

    Master FR done & merged.
  7. Lokesh Choudhary 2018-02-09

    Verified the fix with SDK 7.1.0.v20180209115809. Closing. Studio Ver: 5.0.0.201712081732 OS Ver: 10.13.2 Xcode Ver: Xcode 9.2 Appc NPM: 4.2.12-3 Appc CLI: 7.0.2-master.8 Daemon Ver: 1.0.1 Ti CLI Ver: 5.0.14 Alloy Ver: 1.11.0 Node Ver: 8.9.1 NPM Ver: 5.5.1 Java Ver: 1.8.0_101 Devices: ⇨ google Nexus 5 --- Android 6.0.1 ⇨ google Nexus 6P --- Android 7.1.2
  8. Muhammad Ahmed Fahad 2018-02-12

    Thanks all for the quick fix.

JSON Source