Software Archive
Read-only legacy content
17061 Discussions

Where are the Files ?

phil_J_
New Contributor I
572 Views

I'm following a tutorial for creating & uploading a file to a server, and although I've copied the code it is giving errors.

In it, it shows how to select the Intel XDK File Upload API - which I have done.

Part of the code is;

 

     <script src="intelxdk.js"></script>        
    <script src="cordova.js"></script>          
    <script src="xhr.js"></script>  

  

Yet none of these files are present in my project file system - should they be? DO I need to load these? I was expecting that selecting them in the options would have loaded them.

OR - maybe the error is something else.

 

FYI the code is below, and fails when calling 'upload_to_Server' with the error of alert("Error occurred while getting a pointer to file. Error code is: " + error.code);

function upload_to_server() 
         {
             requestFileSystem(LocalFileSystem.PERSISTENT, 0, onSuccess, onError);
         }
         
         function onSuccess(fileSystem) 
         {   
             var directoryEntry = fileSystem.root;       
             directoryEntry.getFile("readme.txt", {create: true, exclusive: false}, function(fileEntry){
                 fileEntry.createWriter(function(writer){
                     writer.write("This is the text inside readme file");
                     
                     var pathOfFile = fileEntry.fullPath;
                     
                 }, function(error){
                     alert("Error occurred while writing to file. Error code is: " + error.code);
                 });
             }, function(error){
                 alert("Error occurred while getting a pointer to file. Error code is: " + error.code);
             });
         }
         
         function onError(evt)
         {
             alert("Error occurred during request to file system pointer. Error code is: " + evt.code);
         }

 

Thanks for any help

0 Kudos
5 Replies
Anusha_M_Intel1
Employee
572 Views

The intelxdk and xhr libraries are only needed with legacy build tiles. The Cordova library is needed for all. When building with Cordova* tiles, intelxdk and xhr libraries are ignored and so they can be omitted. Also they are phantom libraries that will be added during your build which is why there are only references to them. So that is most probably not the cause of your error. 

Could you link me to the tutorial you are following?

0 Kudos
phil_J_
New Contributor I
572 Views

Thanks for reply

The tutorial is at

http://qnimate.com/uploading-files-and-showing-progress-using-intel-xdk/

I have only embedded the first part 'Creating a text file' into my project with the definitions, and have selected the 'Files' plugins - but get an Error 1 - against the Error occurred while getting a pointer to file alert.

I am trying to learn how to upload a picture file to a server and taking things 1 step at a time. My project so far has a button that takes a picture and then displays it - then I have inserted the button and code as above, and want to get that to work before then trying the 2nd part of the tutorial.

My section of code looks like this;

<!-- ---------------------------------PAGE 3 START --------------------------------------------------- -->
                <div id="uib_page_3" class="upage-content vertical-col hidden">
                    <div class="widget-container content-area vertical-col">

                            <div class="widget uib_w_16 d-margins hdtext" data-uib="media/text" data-ver="0">
                                <div class="widget-container left-receptacle"></div>
                                <div class="widget-container right-receptacle"></div>
                                <div>
                                    <p>Title</p>
                                    <p>Enter details and Upload to the Website</p>
                                </div>
                            </div><span class="uib_shim"></span>
                     </div>
                   
                     <div class="grid grid-pad urow uib_row_2 row-height-2" data-uib="layout/row" data-ver="0">

                        <div class="table-thing with-label widget uib_w_14 d-margins" data-uib="app_framework/input" data-ver="1">
                            <label class="narrow-control label-inline">Reg:</label>

                            <input class="wide-control" type="text">
                        </div><span class="uib_shim"></span>

                        <span class="uib_shim"></span>
                    </div>

                    <div class="table-thing with-label widget uib_w_15 d-margins" data-uib="app_framework/select" data-ver="1">
                        <label class="narrow-control label-inline">Offense:</label>
                        <select class="wide-control">
                            <option>Parking </option>
                            <option>Hogging </option>
                            <option>Throwing </option>
                        </select>
                    </div>
                    <div class="button" id="buttonid" onclick="takepicture()">
                        Take Picture
                    </div>
                    <div>        
                        <img class = "photoone" src="images/EmptyBox-Phone.png" id="photoone"/>
                    </div>
               
                    <button onclick="upload_to_server();">Create and Upload Text File</button>
                    <progress value="0" min="0" max="100" id="progress"></progress>
                </div>
                
                
                <script>
                function upload_to_server() 
        
                {
                    requestFileSystem(LocalFileSystem.PERSISTENT, 0, onSuccess, onError);
                }
         
                function onSuccess(fileSystem) 
                {   
                    var directoryEntry = fileSystem.root;       
                    directoryEntry.getFile("readme.txt", {create: true, exclusive: false}, function(fileEntry){
                    fileEntry.createWriter(function(writer)
                      {
                        writer.write("This is the text inside read me file");
                        var pathOfFile = fileEntry.fullPath;
                       }, function(error){
                        alert("Error occurred while writing to file. Error code is: " + error.code);
                        });
                    }, function(error){
                        alert("Error occurred while getting a pointer to file. Error code is: " + error.code);
                    });
                }
         
                function onError(evt)
                {
                        alert("Error occurred during request to file system pointer. Error code is: " + evt.code);
                }
                
                </script>     
                
        <!-- ---------------------------------PAGE 3 END --------------------------------------------------- -->      

 

 

 

 

 

 

0 Kudos
Anusha_M_Intel1
Employee
572 Views

Hi Phil,

So I followed the tutorial and recreated the project up to creating a text file. My project is attached. It has a little util log window which prints out console.log messages so you can debug the app easily.

Firstly, the error code 1 means NOT_FOUND_ERR (https://github.com/apache/cordova-plugin-file#list-of-error-codes-and-meanings). Secondly, it works fine as a built app. Run my app on an android device and you will see that it creates a readme.txt file on the sdcard. 

It doesn't work on the emulator because Cordova plugins generally consist of two parts: 1) JavaScript API and 2) underlying native code that is specific to the target platform (e.g., Java code for Android, Objective C code for iOS, etc.) The Intel XDK emulator is a simulator that simulates that native part, but only in a very generic way and only for a select number of Cordova APIs. It doesn't actually simulate the underlying functionality, but it does allow you to trace through those parts of your code.

I tried debugging the app using the debug tab. The mainstream XDK debug environment uses an older version of the plugin. The qnimate code is intended for plugin version 1.3.2 and up. We are working on that. (When you build the app, it uses 1.3.2 version of the plugin) 

Intel XDK Early Access debug however, uses 1.3.2 version of the file plugin in the debug environment and so we would encourage anyone using the file API to use Intel XDK Early Access for better debugging facilities. 

0 Kudos
Anusha_M_Intel1
Employee
572 Views

Here's the link to the Intel XDK Early Access download site by the way: https://software.intel.com/en-us/intel-xdk/early-access#downloadea

You can post any EA specific questions on this forum: https://software.intel.com/en-us/forums/intel-xdk-early-access

0 Kudos
phil_J_
New Contributor I
572 Views

Thanks Anusha will work on it tomorrow

0 Kudos
Reply