Software Archive
Read-only legacy content
17061 Discussions

Upload To Server

Brian_K_1
Beginner
670 Views

Hi team,

I am working on a project in which I need to upload an image to a server using XDK code as shown below.

intel.xdk.file.uploadToServer(pictureURL,"http://www.myserver.com/uploadImage.php", "", "image/jpeg", "updateUploadProgress");

I have two issues:

1. The callback gives a success yet the upload does not even reach the server URL, what could be failing?

2. Is there a way of adding more parameters to describe the upload?

Please assist, thanks.

0 Kudos
2 Replies
John_H_Intel2
Employee
670 Views

1. Do you have the appropriate permissions on the folder you are trying to upload to?

2. No. 

It will not work in the XDK you have to build and test it on device.

0 Kudos
Brian_K_1
Beginner
670 Views

Hi John,

Thanks for the quick reply,

1. Yes, I have given all the appropriate permissions infact ive given all permissions 777. What else could I be doing wrong? Please see my code snippet below:

 

        <script>
            function captureCamera()
            {
                intel.xdk.camera.takePicture(10,true,"png");
            }
           
            function importLibrary()
            {
                intel.xdk.camera.importPicture();
            }
           
            document.addEventListener("intel.xdk.camera.picture.add",function(event){
                var name = event.filename;
                var url = intel.xdk.camera.getPictureURL(name);
                document.getElementById("picture").setAttribute("src", url);
               alert(url);
              intel.xdk.file.uploadToServer(url,"http://wiseapp.mobi/apphour/index.php", "name", "image/png", "updateUploadProgress"); 
                
            alert("Request sent");
            });
           
            document.addEventListener("intel.xdk.camera.picture.busy",function(){
                alert("Camera is already in use");
            });
           
            document.addEventListener("intel.xdk.camera.picture.cancel",function(){
                alert("You pressed the cancel button");
            });
           
            function updateUploadProgress(bytesSent,totalBytes)
            {
               if(totalBytes>0)
                    currentProgress=(bytesSent/totalBytes)*100;
                document.getElementById("progress").setAttribute("value", currentProgress);
            }
    
            document.addEventListener("intel.xdk.file.upload.busy",uploadBusy);
            document.addEventListener("intel.xdk.file.upload",uploadComplete);
            document.addEventListener("intel.xdk.file.upload.cancel",uploadCancelled);
    
            function uploadBusy(evt)
            {
               alert("Sorry, a file is already being uploaded");
            }
    
            function uploadComplete(evt)
            {
               if(evt.success==true)
               {
                  alert("Image was uploaded");
                   
               }
               else {
                  alert("Error uploading file "+evt.message);
               }
            }
    
            function uploadCancelled(evt)
            {
                alert("File upload was cancelled "+evt.localURL);
            }
            
            
            </script>

 

2. Ok, thanks anyway.

 

0 Kudos
Reply