IPWorks Cloud 2020 macOS Edition

Questions / Feedback?

UploadFile Method

Will upload a file to a folder.

Syntax

public func uploadFile(fileName: String, parentId: String) throws -> String

Remarks

The method when called will upload a file specified in the LocalFile property. If LocalFile has not been set then the class will use the data found in the ItemData property; The file will be uploaded to the folder specified by the ParentId parameter. The name of the file will be what is passed to the FileName parameter. Once it has completed uploading it will return the id of the uploaded file.

Note that the string root may be used as a ParentId to represent the root folder, and the string home may be used as a folder Id to represent the home folder for the current user. Other special id's include:

  • favorites
  • allshared
  • connectors
  • box
  • top

Name Conflict Resolution

The class will overwrite a file if a file is uploaded to the same folder with the same name.

If LocalFile is set the file will be uploaded from the specified path. If LocalFile is not set the data in ItemData will be used.

To encrypt the file before uploading it, set EncryptionAlgorithm and EncryptionPassword.

Upload Notes

ShareFile 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.

ShareFile.LocalFile = "../MyFile.zip";
ShareFile.UploadFile("/MyFile.zip");

Resumable

To enable resumable uploads set UseResumableUpload to . This is recommended for large files. The class will automatically fragment the specified file into smaller pieces and upload each individually.

When UseResumableUpload is set to and UploadFile is called, a resumable upload session is started by the class. Once called and the class fragments the file, the ResumeURL property is populated. This URL needs to be set so that the class can resume the upload if the upload is interrupted.

During a resumable upload, the FragmentComplete event fires after each fragment is uploaded to indicate overall progress. The class also updates StartByte as necessary to indicate the current offset in the file.

If the upload is interrupted for any reason, resuming it is easy. First, verify that ResumeURL and StartByte are populated (if the same instance of the class is used, they should already be populated, and no special action should be needed). Then call UploadFile again to resume the upload at the specified StartByte offset.

Note that if the upload is not resumed after some time the upload session will expire.

shareFile.UseResumableUpload = true;
shareFile.LocalFile = "../MyFile.zip";
shareFile.UploadFile("MyFile.zip");

// The transfer is interrupted and UploadFile() above fails. Later, resume the download.
// Using the same instance StartByte and ResumeURL are already populated from the previous
// upload attempt.
shareFile.UploadFile("MyFile.zip");

Copyright (c) 2022 /n software inc. - All rights reserved.
IPWorks Cloud 2020 macOS Edition - Version 20.0 [Build 8265]