Using FileTransfer to upload a file but getting a Null error for Code, Source and Target

10 posts, 2 answers
  1. Brad
    Brad avatar
    8 posts
    Member since:
    Dec 2008

    Posted 29 Dec 2013 Link to this post

    I'm testing with the Camera Sample project and using  the _onPhotoURISuccess callback to call the following function.  The image displays fine but I'm getting Null in the Error callback for the FileTransfer upload method for Code, Source and Target.

    I've tried the tried using Asp.net Web Api and a regular MVC controller but neither are hit by the FileTransfer upload call.

    function uploadPhoto(imageURI) {
         
         var options = new FileUploadOptions();
         options.fileKey = "file";
         options.fileName = imageURI.substr(imageURI.lastIndexOf('/') + 1);
         options.mimeType="image/jpeg";
         
         var params = {};
         params.value1 = "test";
         params.value2 = "param";
         options.params = params;
     
        options.chunkedMode = false;
         
         
         var ft = new FileTransfer();
         ft.upload(imageURI, encodeURI("http://localhost:50374/photo/upload"), win, fail, options);
    }

    Thanks,
    Brad
  2. Brad
    Brad avatar
    8 posts
    Member since:
    Dec 2008

    Posted 29 Dec 2013 Link to this post

    I used the the solution from the following post  http://www.icenium.com/resources/forums/icenium-mist-/in-simulator-my-file-upload-working-but-in-apple-ipad-its-not-working  under the link Upload a File to a Remote Server with PhoneGap but I'm having the same issue with getting nulls in the error callback.

    I have a regular Asp.NET MVC form that posts a file upload to the the same controller and it's able to hit it fine.  It's just from the Graphite IDE.

    <!DOCTYPE html>
    <!--
        Licensed to the Apache Software Foundation (ASF) under one
        or more contributor license agreements.  See the NOTICE file
        distributed with this work for additional information
        regarding copyright ownership.  The ASF licenses this file
        to you under the Apache License, Version 2.0 (the
        "License"); you may not use this file except in compliance
        with the License.  You may obtain a copy of the License at
     
     
        Unless required by applicable law or agreed to in writing,
        software distributed under the License is distributed on an
        "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
         KIND, either express or implied.  See the License for the
        specific language governing permissions and limitations
        under the License.
    -->
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
            <meta name="format-detection" content="telephone=no" />
            <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
            <link rel="stylesheet" type="text/css" href="css/index.css" />
            <title>Hello World</title>
            <script type="text/javascript" src="cordova.js"></script>
            <script type="text/javascript" src="js/index.js"></script>
            <script type="text/javascript" charset="utf-8">
      
            // Wait for PhoneGap to load
            document.addEventListener("deviceready", onDeviceReady, false);
      
            // PhoneGap is ready
            function onDeviceReady() {
            // Do cool things here...
            }
      
            function getImage() {
                // 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,
                sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY
            }
                );
      
            }
      
            function uploadPhoto(imageURI) {
                console.log('in the function');
                var options = new FileUploadOptions();
                options.fileKey="file";
                options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1);
                options.mimeType="image/jpeg";
                 console.log('settings parms');
                var params = new Object();
                params.value1 = "test";
                params.value2 = "param";
      
                options.params = params;
                options.chunkedMode = false;
                 alert('transferring...');
                var ft = new FileTransfer();
                ft.upload(imageURI, "http://localhost:50374/photo/upload", win, fail, options);
            }
      
            function win(r) {
                console.log("Code = " + r.responseCode);
                console.log("Response = " + r.response);
                console.log("Sent = " + r.bytesSent);
                alert(r.response);
            }
      
            function fail(error) {
                alert("An error has occurred: Code = " + error.code);
            }
      
            </script>
        </head>
        <body>
            <div class="app">
                <h1>Apache Cordova</h1>
                <div id="deviceready" class="blink">
                    <p class="event listening">Connecting to Device</p>
                    <p class="event received">Device is Ready</p>
                </div>
            </div><br/><br/>
            <button onclick="getImage();">Upload a Photo</button>
             
            <script type="text/javascript">
                app.initialize();
            </script>
        </body>
    </html>
  3. Answer
    Brad
    Brad avatar
    8 posts
    Member since:
    Dec 2008

    Posted 31 Dec 2013 Link to this post

    Hi Brad,

    Are you testing your code in the simulator or on a device? If you're testing on a device, then you should change "http://localhost" to whatever the actual IP or host name of your development machine is.

    Regards,
    Stefan
    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.
  4. Brad
    Brad avatar
    8 posts
    Member since:
    Dec 2008

    Posted 31 Dec 2013 Link to this post

    Thanks Stefan!

    I was using the emulator but was able to hit the service with the device when pushed to the remote host.  I also switched to using the ip address when testing locally but I still can't use the FileTransfer within the simulator - only on the device.  I'm guessing this is a limitation with the plugin in the emulator.

    Brad
  5. Answer
    Stefan
    Admin
    Stefan avatar
    198 posts

    Posted 31 Dec 2013 Link to this post

    Hi Brad,

    The simulator actually does not currently support the File and File Transfer API. I should have noticed this issue in the first place. Support for both in the simulator is coming in the next official release. Here's a list of limitations of the simulator.

    Regards,
    Stefan
    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.
  6. Ramesh
    Ramesh avatar
    3 posts
    Member since:
    Nov 2014

    Posted 20 Nov 2014 in reply to Brad Link to this post

    Hi Brad ,
     May i Know what are the plugins used for this...
     am using Device,camera,console,filetransfer and file
     however i cant acces FileTransfer upload call
     
  7. Ramesh
    Ramesh avatar
    3 posts
    Member since:
    Nov 2014

    Posted 20 Nov 2014 in reply to Brad Link to this post

    Hi Brad ,
     May i Know what are the plugins used for this...
     am using Device,camera,console,filetransfer and file
     however i cant acces FileTransfer upload call
     
    Thanks & Regards
    Ramesh Sundar
  8. Brad
    Brad avatar
    8 posts
    Member since:
    Dec 2008

    Posted 20 Nov 2014 in reply to Ramesh Link to this post

    Ramesh,  I was using the filetransfer and it was a limitation of the simulator.  It worked fine on the actual device.
  9. Ramesh
    Ramesh avatar
    3 posts
    Member since:
    Nov 2014

    Posted 20 Nov 2014 in reply to Brad Link to this post

    Hi Brad,
     Thanks for your response 
     Another think i want to know from you
     Am using windows 7, can you tell which simulator is best or suitable to check my app for ipad

    Thanks
    Robert 
     
  10. Kaloyan
    Admin
    Kaloyan avatar
    872 posts

    Posted 25 Nov 2014 Link to this post

    Hi Ramesh,

    I would recommend the AppBuilder's built in iPad simulator. You can access it, from any of our clients, by changing the device to iPad. Please, refer to this article for more details, about how to run the AppBuilder simulator. And, here you can see how to configure the desired simulated device.

    I hope this helps.

    Regards,
    Kaloyan
    Telerik
     

    Visit the Telerik Verified Plugins Marketplace and get the custom Cordova plugin you need, already tweaked to work seamlessly with AppBuilder.

     
Back to Top