Uploading files to a server
Now that we've got a script on a server that's waiting for us to upload content, we can use the File Transfer plugin to do just that. Instead of calling download
, we'll be calling upload
, as you might expect. This does require some options to be set, so it's not quite as simple as calling download
.
upload
accepts several parameters:
fileToUpload
indicates the file stored on the local device that you want to upload. Use thecdvfile://
file path.uploadURL
is the URL of your upload script. This should be passed through encodeURI.uploadSuccess
will be called if the upload was successful.uploadError
will be called if the upload didn't complete successfully.options
specifies the file key, name, and mime type at a minimum. It can also supply parameters, headers, and other useful settings. This is an instance ofFileUploadOptions
.
Note
The snippets in this section are located at snippets/09/ex2-uploading-files
in the code package of this book. When using the interactive...