Code Sample for FileTransfer

11 posts, 0 answers
  1. Ashish
    Ashish avatar
    5 posts
    Member since:
    Nov 2012

    Posted 11 Feb 2013 Link to this post

    Is there any code sample available on using FileTransfer.Download API. I keep getting "Uncaught ReferenceError: FileTransfer is not defined" in the simulator console window.

    Here is the code:

    function transferFile(fileSystemPath){
        var transfer = new FileTransfer(),
        uri = encodeURI("http://icenium.com/assets/img/icenium-logo.png");
        filePath = fileSystemPath+'/sample.png';
        transfer.download(
            uri,
            filePath,
            function(entry) {
                var image = document.getElementById("result");
                image.src=entry.fullPath;
            },
            function(error) {
                console.log("download error source " + error.source);
                console.log("download error target " + error.target);
                console.log("upload error code" + error.code);
            }
        );
    }
  2. Ashish
    Ashish avatar
    5 posts
    Member since:
    Nov 2012

    Posted 11 Feb 2013 Link to this post

    Got response on Github. Essentially response is, yes there's sample code on FileTransfer, but they don't work in Simulator.
    https://github.com/Icenium/sample-file-transfer/issues/1
  3. divya
    divya avatar
    5 posts
    Member since:
    Jan 2014

    Posted 31 Jan 2014 Link to this post

     hi,
    i am working on fileupload  to server using phonegap.when i am running in appbuilder simulator "error code=3" error is showing. i searched in google but i am not found any solution.what it means? and how to resolve?
  4. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 31 Jan 2014 Link to this post

    Hi divya,

    Error 3 is connection error, you can see the errors in the respective Cordova file for the core plugin you're using. We've added support for Cordova FileTransfer plugin in the AppBuilder simulator in the latest version released early this week, so make sure you're up to date.

    Also does your app function correctly if deployed on an actual app (not simulator)?

    Regards,
    Steve
    Telerik
    Icenium is now Telerik AppBuilder, and is part of the Telerik Platform. For more information on the new name, and to learn more about the Platform, register for the free online keynote and webinar on Wednesday, February 12, 2014 at 11:00 a.m. ET (8:00 a.m. PT)
  5. divya
    divya avatar
    5 posts
    Member since:
    Jan 2014

    Posted 02 Feb 2014 Link to this post

    this is my code,  can any body tell me where is the error(error code :3)

     (function (global) {
        var submitViewModel,
            app = global.app = global.app || {};

        submitViewModel = kendo.data.ObservableObject.extend({
           

            onsubmit: function () {
                // Wait for device API libraries to load
            //
            document.addEventListener("deviceready", onDeviceReady, false);

            // device APIs are available
            //
            function onDeviceReady() {
                // Retrieve image file location from specified source
                navigator.camera.getPicture(
                    uploadPhoto,
                    function(message) { alert('get picture failed'); },
                    {
                        quality         : 50,
                        destinationType : navigator.camera.DestinationType.FILE_URI
                    }
                );
            }
               

            function uploadPhoto(imageURI) {
                
                var options = new FileUploadOptions();
               
                options.fileKey="file";
                options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1);
                options.mimeType="image/jpeg";
                options.chunkedMode = false;
                alert(options.fileName);
               //options.headers = {
               //  Connection: "close"
               //    }

                    
                        var params = new Object();
                        params.ProfileId = "12345";
                        params.ProductLeadType = "1";
                        params.ProductLeadName = "test";
                        params.ProductLeadDesc = "test desc";
                      //  options.params = params;
                         
               
                    // Transfer picture to server
                var ft = new FileTransfer();
                
                ft.upload(imageURI, "http://115.119.249.70/tobocwebservices.asmx/SaveImage", win, fail, options,true);
            }
                  
            function win(r) {
                console.log("Code = " + r.responseCode);
                console.log("Response = " + r.response);
                console.log("Sent = " + r.bytesSent);
            }

            function fail(error) {
                
                alert("An error has occurred: Code = " + error.code);
             //   console.log("upload error source " + error.source);
             //   console.log("upload error target " + error.target);
            }

            
          }      
        });

        app.submitService = {
            viewModel: new submitViewModel()
        };
    })(window);
  6. divya
    divya avatar
    5 posts
    Member since:
    Jan 2014

    Posted 02 Feb 2014 in reply to divya Link to this post

    I tested in device  but it showing same error
  7. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 04 Feb 2014 Link to this post

    Hello divya,

    There is nothing visibly wrong with the code, you can use remote debugging tools like jsHybugger and Weinre to try to pinpoint what is going wrong. You can also setup Fiddler to intercept your device's traffic which would give you a clue what's going on if the problem is failing/wrong requests/responses.

    Regards,
    Steve
    Telerik
    Icenium is now Telerik AppBuilder, and is part of the Telerik Platform. For more information on the new name, and to learn more about the Platform, register for the free online keynote and webinar on Wednesday, February 12, 2014 at 11:00 a.m. ET (8:00 a.m. PT)
  8. Michael
    Michael avatar
    151 posts
    Member since:
    Jan 2012

    Posted 04 Feb 2014 Link to this post

    Divya,

    Try these settings:

                destinationType: navigator.camera.FILE_URI,
                encodingType : navigator.camera.EncodingType.JPEG, 
                quality: 40,
                targetWidth: 500,
                targetHeight: 500,
                saveToPhotoAlbum: 1

    and something like this:

            uploadPhoto: function (imageURI) {
                var options = new FileUploadOptions();
               
                options.chunkedMode = false;
                options.headers = {
                   Connection: "close"
                };

                // setup parameters
                var params = {};
                params.fullpath = imageURI;
                params.name = options.fileName;

                var ft = new FileTransfer(); 
                ft.upload(imageURI, encodeURI("http://your-path"), win, fail, options, true);
            } 





  9. Michael
    Michael avatar
    151 posts
    Member since:
    Jan 2012

    Posted 04 Feb 2014 Link to this post

    we spent a week on this same problem, and it all came down to that extra "true" parameter on the upload, setting the file dimensions and making sure savetophotoalbum was set.

    error code 1 and 3 were never server errors. they were always just fileupload failing and not giving a proper reason why.
  10. divya
    divya avatar
    5 posts
    Member since:
    Jan 2014

    Posted 10 Feb 2014 Link to this post

    I debugged above code,error is rising in cordova.js file and line is

    ICE_CordovaExecutionProcessor.Execute(service, action, callbackId, JSON.stringify(args)); here
    service:filetransfer
    action:upload
    callbackId:FileTransfer931564722
    how to resolve this?

  11. Marc
    Marc avatar
    1 posts
    Member since:
    Jan 2016

    Posted 16 Mar Link to this post

    Michael your settings changes were the answer for me, I've spent most of the day trying to figure out code 1 and 3 errors. All working now. Thanks
Back to Top