uploadToServer

This method uploads files to a remote server over the Internet

intel.xdk.file.uploadToServer(localURL, uploadURL, folderName, mimeType, uploadProgressCallback);

Description:

Use this command to upload a file to a server on the Internet.

Platforms:

Parameters:

  • localURL: The URL of the file on the local device server. This URL will always start with http://localhost:58888/.
  • uploadURL: The remote server address that the file will be uploaded to
  • folderName: The name of the folder on the remote server to hold the transferred file
  • mimeType: The mime type of the file to be uploaded
  • uploadProgressCallback: The function named here is called repetitively as the file uploads. The function should include two parameters. The first will be the number of bytes sent so far and the second will be the total bytes to be uploaded.

Example:


//Get the image to upload
var pictureURL=intel.xdk.camera.getPictureURL(pictureFilename);

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

function updateUploadProgress(bytesSent,totalBytes)
{
   if(totalBytes>0)
        currentProgress=(bytesSent/totalBytes)*100;
   document.getElementById("progress").innerHTML=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("File "+evt.localURL+" was uploaded");
   }
   else {
      alert("Error uploading file "+evt.message);
   }
}

function uploadCancelled(evt)
{
    alert("File upload was cancelled "+evt.localURL);
}       
            
For more complete information about compiler optimizations, see our Optimization Notice.