UploadFile Method
Uploads a file.
Syntax
dropbox.uploadFile(fileName, [callback])
Callback
The 'callback' parameter specifies a function which will be called when the operation completes (or an error is encountered). If the 'callback' parameter is not specified, then the method will block and will not return until the operation completes (or an error is encountered).
The callback for this method is defined as:
function(err, data){ }
'err' is the error that occurred. If there was no error, then 'err' is 'null'.
'data' is the value returned by the method.
'err' has 2 properties which hold detailed information:
err.code err.message
Remarks
This method uploads a file. LocalFile specifies the file to upload. The data to upload may also be set in ResourceData .
The FileName parameter of UploadFile specifies the name of the file to be written.
A file can be uploaded to a specific folder by specifying the absolute path in the FileName parameter,
or by setting ResourcePath to the folder. Absolute paths begin with a "/" character and must include the full
path beginning at the root. For instance:
//Upload to the root folder dropbox.ResourcePath = ""; string path = dropbox.UploadFile("test.txt"); //path is "/test.txt" //Upload to a folder (relative path) dropbox.CreateFolder("/uploadtest"); path = dropbox.UploadFile("test.txt"); //path is "/uploadtest/test.txt" //Upload to a folder (absolute path) path = dropbox.UploadFile("/uploadtest/test.txt"); //path is "/uploadtest/test.txt"
To encrypt a file before uploading set EncryptionAlgorithm and EncryptionPassword.
When the upload is complete the class will fire the UploadComplete event and UploadFile returns the absolute path to the uploaded file.
Upload Notes
Dropbox offers two ways to upload a file. For smaller files a simple upload option is provided to upload data in one request. This is the default option. For larger files uploads can be fragmented into multiple pieces, allowing resuming of uploads that may be interrupted.
Simple
By default the class uses the simple upload mechanism.
dropbox.LocalFile = "../MyFile.zip"; dropbox.UploadFile("/folder/MyFile.zip");
The following properties are applicable when calling UploadFile and UseResumableUpload if False (default - simple upload):
Resumable
To enable resumable uploads set UseResumableUpload to True. This is recommended for large files. The class will automatically fragment the specified file into smaller pieces and upload each individually. FragmentSize may be set to specify the size of the fragment if desired. The default fragment size is 10 MB.
When UseResumableUpload is set to True and UploadFile is called a resumable upload session is started by the class. UploadSessionId is populated with the Id of the session. This value may be needed for additional operations if the upload does not complete normally. Additionally StartByte is updated as necessary by the class to indicate the current offset in the file.
If the upload is interrupted for any reason the upload may be resumed. To resume an upload verify that UploadSessionId and StartByte are populated. If the same instance of the class is used these should already be populated and no special action is needed. Call UploadFile again to resume the upload at the specified StartByte offset.
The FragmentComplete event fires after each fragment is uploaded to indicate overall progress.
dropbox.LocalFile = "../MyFile.zip"; dropbox.UploadFile("MyFile.zip"); //The transfer is interrupted and UploadFile() above fails. Later, resume the download. //Using the same instance StartByte and UploadSessionId are already populated //from the previous upload attempt dropbox.UploadFile("MyFile.zip");
The following properties are applicable when calling UploadFile and UseResumableUpload if True: