Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-23125] Windows: getting photo from gallery fails

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2016-06-28T03:45:07.000+0000
Affected Version/sRelease 5.2.1
Fix Version/sRelease 5.4.0
ComponentsWindows
Labelsgallery, image, media, qe-5.4.0
ReporterZakhar Zhuravlev
AssigneeKota Iguchi
Created2016-03-24T14:24:04.000+0000
Updated2016-06-28T17:08:07.000+0000

Description

It's affected 5.2.0 Error code: -1; Error message: 'Failed to load content from file' *index.js:*
function onTest() {
	Titanium.Media.openPhotoGallery({
 		mediaTypes: [Ti.Media.MEDIA_TYPE_PHOTO],
		success: function(e) {
			$.imageView.image = e.media;
		},
		error: function(error) {			
			Titanium.UI.createAlertDialog({
				title: error.code,
				message: error.error,
				ok: 'ok'
			}).show();
		}
	});
}

$.win.open();
*index.xml:* {noformat}

Comments

  1. Kota Iguchi 2016-03-31

    There are two issues related to this. One is you needed to configure picturesLibrary capability in tiapp.xml to enable permission to access Windows photo library. The other issue is TIMOB-23115, because of that ImageView doesn't accept Blob. So this issue actually depends on TIMOB-23115. Also we'll need to update the document so we can find appropriate configuration easily.
       <windows>
         <manifest>
           <Capabilities>
             <Capability Name="internetClient" /> <!-- in case you need Internet connection -->
             <Capability Name="picturesLibrary" /><!-- This line is required to request access to the photo library -->
           </Capabilities>
         </manifest>
       </windows>
       
  2. Kota Iguchi 2016-04-01

    Confirmed that latest CI build (5.4.0.v20160331110910) fixes the issue. You can checkout latest build via ti sdk install -b master -d. Note that you'll need to set picturesLibrary to your tiapp.xml to get access to Windows pictures library like blow.
       <windows>
         <manifest>
           <Capabilities>
             <Capability Name="internetClient" /> <!-- in case you need Internet connection -->
             <Capability Name="picturesLibrary" /><!-- This line is required to request access to the photo library -->
           </Capabilities>
         </manifest>
       </windows>
       
  3. Josh Longton 2016-06-13

    I am still able to reproduce this issue using: *Device:* Windows Phone 10.0 *Node.js Version:* 4.4.4 *npm Version:* 4.2.7-2 *Titanium SDK:* 5.4.0.v20160608165242 *Appcelerator CLI Version:* 5.4.0-15 *Appcelerator Studio:* 4.6.0.201605201934 I have added the code below the the TiApp and used the demo code in the comments above:
           <windows>
               <manifest>
                   <Capabilities>
                       <Capability Name="internetClient"/>
                       <!-- in case you need Internet connection -->
                       <Capability Name="picturesLibrary"/>
                       <!-- This line is required to request access to the photo library -->
                   </Capabilities>
               </manifest>
           </windows>
       
    *Reopening ticket*
  4. Kota Iguchi 2016-06-14

    Turns out it's a regression. 5_4_X: https://github.com/appcelerator/titanium_mobile_windows/pull/742 master: https://github.com/appcelerator/titanium_mobile_windows/pull/743
  5. Christopher Williams 2016-06-17

    Sounds like Ewan was able to confirm the fix, so I merged the fixes to 5_4_X and master.
  6. Josh Longton 2016-06-27

    I am still able to reproduce this issue application crashes or just shows a black screen using: *Device:* Windows Phone 10.0, 8.1 *Node.js Version:* 4.4.4 *npm Version:* 4.2.7-2 *Titanium SDK:* 5.4.0.v20160627120037 *Appcelerator CLI Version:* 5.4.0-18 *Appcelerator Studio:* 4.7.0.201606150733 *App.js*
       var window = Ti.UI.createWindow({
           exitOnClose: true,
       });
       var viewParent = Ti.UI.createView({
           width: '60%',
           height: '41%',
           top: '1%'
       });
       
       var imageTaken = Ti.UI.createImageView({
           width: Ti.UI.FILL,
           height: Ti.UI.FILL,
       });
       
       var cameraImage = Ti.UI.createButton({
           title: "Choose Photos",
           bottom: '0%',
           height: '20%',
           font: {
               fontSize: 15,
               fontWeight: "bold"
           },
           width: Ti.UI.FILL,
       });
       
       viewParent.add(imageTaken);
       viewParent.add(cameraImage);
       window.add(viewParent);
       
       cameraImage.addEventListener('click', function (e) {
       
           Ti.Media.openPhotoGallery({
               autoHide: true,
               mediaTypes: [Ti.Media.MEDIA_TYPE_PHOTO],
               success: function (e) {
                   if (e.mediaType === Ti.Media.MEDIA_TYPE_PHOTO) {
                       imageTaken.image = e.media;
                       Ti.API.info(JSON.stringify(e));
                       Ti.API.info(imageTaken.image);
                   }
               },
               cancel: function () {
               },
               error: function (err) {
                   Ti.API.error(err);
               }
           });
       
       });
       window.open();
       
    *Added to the Tiapp.xml*
           <windows>
               <manifest>
                   <Capabilities>
                       <Capability Name="internetClient"/>
                       <!-- in case you need Internet connection -->
                       <Capability Name="picturesLibrary"/>
                       <!-- This line is required to request access to the photo library -->
                   </Capabilities>
               </manifest>
           </windows>
       
    *Reopening*
  7. Kota Iguchi 2016-06-28

    [~jlongton] I was able to reproduce the crash, and it turns out it was because of JSON.stringify against Blob. When I remove JSON.stringify from success callback, it went through well for me. Can you try following?
               success: function (e) {
                   if (e.mediaType === Ti.Media.MEDIA_TYPE_PHOTO) {
                       imageTaken.image = e.media;
                   }
               },
       
    So if that's the case, it is because of Blob, not because of Ti.Media.openPhotoGallery. I would resolve this ticket, and create new ticket for Blob: TIMOB-23568
  8. Josh Longton 2016-06-28

    Verified as fixed. Tested on: Microsoft Lumia 640 (8.1) Microsoft Lumia 640 (10) Windows 10 Pro Studio: 4.7.0.201606150733 Ti SDK: 5.4.0.v20160627224205 Appc NPM: 4.2.7-2 App CLI: 5.4.0-20 Node v4.4.4 *Closing Ticket.*

JSON Source