Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-25282] Windows: saveToPhotoGallery throws exception

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2017-10-09T12:57:27.000+0000
Affected Version/sRelease 6.1.2, Release 7.0.0, Release 6.2.0
Fix Version/sRelease 7.0.0
ComponentsWindows
Labelsn/a
ReporterEwan Harris
AssigneeKota Iguchi
Created2017-09-14T16:29:30.000+0000
Updated2018-08-06T17:49:12.000+0000

Description

Description

Calling Ti.Media.saveToPhotoGallery() throws the following error, running through VS gives more detail and I believe the cause is [to_path here](https://github.com/appcelerator/titanium_mobile_windows/blob/7f4b3efcac026b1b6037b59ad1904556c826db21/Source/Media/src/Media.cpp#L377) is null, so the to convert string call is returning an empty string, which then causes an error in the copy call. I believe this is because the Library folders are virtualized [read here](https://stackoverflow.com/questions/38874259/windows-storage-knownfolders-musiclibrary-path-returns-empty) so they don't have a path, we might need to do something like [this](https://github.com/Microsoft/Windows-universal-samples/blob/6370138b150ca8a34ff86de376ab6408c5587f5d/Samples/FileAccess/cpp/Scenario1_CreateAFileInThePicturesLibrary.xaml.cpp#L31-L48) to first find the folder for a user, then write to that folder
[ERROR] ----- Titanium Javascript Runtime Error -----
[ERROR] In app.js: 14,28
[ERROR] Message: Uncaught Error: saveToPhotoGallery: unknown exception
var win = Ti.UI.createWindow();
var view = Ti.UI.createView({
    backgroundColor: 'red',
    width: 400,
    height: 400,
    borderRadius: 200
});
win.add(view);
win.open();
var file = Ti.Filesystem.getFile('Logo.png')
Ti.Media.saveToPhotoGallery(file, {
    success: function (e) {
        // log.args('Ti.Media', 'Image saved to photo-gallery successfully!');
        console.log('image done');
    },
    error: function (e) {
        // log.args('Ti.Media', 'Error saving image to photo-gallery: ' + e.error);
        console.log(JSON.stringify(e))
        console.log('image ');
    }
});

Steps to reproduce

Add the above to an existing app.js and build for Windows

Actual

Error thrown

Expected

Image should be written to gallery

Comments

  1. Kota Iguchi 2017-10-02

    https://github.com/appcelerator/titanium_mobile_windows/pull/1127
  2. Eric Merriman 2018-08-06

    Cleaning up older fixed issues. If this issue should not have been closed as fixed, please reopen.

JSON Source