Cordova File API

8 posts, 0 answers
  1. Joe
    Joe avatar
    2 posts
    Member since:
    Oct 2013

    Posted 27 Nov 2013 Link to this post

    Hi,

    I've been working with the File API that is available from Cordova for working with photos and then uploading those images.  I'm running into issues with the FileEntry class and also the FileTransfer class.  Here are some code snippets, I've remarked out the FileTransfer call in this example:

    var img = new Image();
    img.style.display = 'block';
    img.src = "http://localfile/Simulator////C:/Users/me/Pictures/bus.png";

    var App = {
            CachedPictures[{ID: 0, ImageBinary: img, ImageNm: "xx", ImageNotes: "xxxx"}],
            SavePicture: function () {
                for (var i = 0; i < App.CachedPictures.length; i++) {
                   
                    var lastImage = App.CachedPictures[App.CachedPictures.length - 1];
                    var url = 'SomeURL?ImageNm=' + encodeURIComponent(lastImage.ImageNm) +
                                '&ImageNotes=' + encodeURIComponent(lastImage.ImageNotes);

                    // get instance of file object
                    var filePath = lastImage.ImageBinary.src.substr(lastImage.ImageBinary.src.lastIndexOf('///') + 3);
                    console.log("filePath:\t" + filePath);
                    var file = null;
                    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0,
                        function (fileSystem) {
                            fileSystem.root.getFile(filePath, { create: true, exclusive: false },
                                function (parent) {
                                    console.log(parent);
                                },
                                function () {
                                    console.log("** error getting file");
                                });
                        },
                        function (evt) {
                            console.log('** failed in file system request')
                            console.log(evt);
                        });

    /*                var imageURI = lastImage.ImageBinary.src;
                    var options = new FileUploadOptions();
                    options.fileKey = "file";
                    options.fileName = imageURI.substr(imageURI.lastIndexOf('/') + 1);
                    console.log(options.fileName);
                    options.mimeType = "text/plain";

                    console.log('*** original image source');
                    console.log(lastImage.ImageBinary.src);
                    console.log('*** modified path');
                    console.log(options.fileName);
                   

                    var ft = new FileTransfer();
                    ft.upload(imageURI, url,
                        function (r) {
                            console.log("Code = " + r.responseCode);
                            console.log("Response = " + r.response);
                            console.log("Sent = " + r.bytesSent);
                        },
                        function (error) {
                            // error.code == FileTransferError.ABORT_ERR
                            alert("An error has occurred: Code = " + error.code);
                            console.log("upload error source " + error.source);
                            console.log("upload error target " + error.target);
                        },
                        options);
                    ft.abort();*/
                }
            }
    }

    When trying to use the file FileEntry class i get the following in my console.log call:

    filePath: C:/Users/me/Pictures/bus.png App.js:152

    ** failed in file system request App.js:165

    FileError {code: "Not Supported in Simulator"}


    Is there a plan in the future to support the Cordova File APIs from the simulator?

    Joe
  2. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 27 Nov 2013 Link to this post

    Hello Joe,

    As you have found the hard way, Cordova File API is not supported in the Icenium Simulator. We do plan to add support for all core Cordova APIs (now plugins) into the Simulator. File API would be one of the first, with support comming as early as end of January 2014.

    Regards,
    Steve
    Telerik
    You've missed the Icenium Visual Studio Integration keynote? It has been recorded and posted here.
    Looking for tips & tricks directly from the Icenium team? Check out our blog!
    Share feedback and vote for features on our Feedback Portal.
  3. Amir
    Amir avatar
    3 posts
    Member since:
    Dec 2013

    Posted 13 Dec 2013 Link to this post

    steve pls
  4. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 14 Dec 2013 Link to this post

    Hi Amir,

    As noted in our previous post, the Cordova File API would be added to the Icenium Simulator in the next major version of the product.

    Regards,
    Steve
    Telerik
    You've missed the Icenium Visual Studio Integration keynote? It has been recorded and posted here.
    Looking for tips & tricks directly from the Icenium team? Check out our blog!
    Share feedback and vote for features on our Feedback Portal.
  5. Bala Chandra V
    Bala Chandra V avatar
    10 posts
    Member since:
    May 2014

    Posted 13 May 2014 Link to this post

    Is this support Added? I am having more or less same issue?
  6. Paul-Henri
    Paul-Henri avatar
    14 posts
    Member since:
    Mar 2014

    Posted 13 May 2014 Link to this post

    I have the same issue, is there another way to do so?
  7. Kaloyan
    Admin
    Kaloyan avatar
    872 posts

    Posted 15 May 2014 Link to this post

    Hi,

    The support for the Cordova File API is added in the simulator functionality for all of the AppBuilder clients except the In-Browser client. You can check this here. To try it out, you can check our File Sample, which successfully writes, reads and deletes files from your computer. Note, you might need to adjust the Root Folders Location accordingly to your scenario and account permissions.

    Further, the simulator (except the one in the In-Browser client) also supports the Cordova FileTransfer API. You will find the sample project for it, here.

    I hope this helps. Please, let me know if there is anything more particular that prevents you for using the above APIs and I will be glad to assist you further.

    Regards,
    Kaloyan
    Telerik
     

    Share what you think about AppBuilder and Telerik Platform with us in our feedback portal, so we can become even better!

     
  8. jerome
    jerome avatar
    1 posts
    Member since:
    Sep 2014

    Posted 20 Sep 2014 Link to this post

    This is a real bugger, I have nearly the same situation I was hoping I could find similar from the wealth factory review
Back to Top