IPWorks Cloud 2020 Android Edition

Questions / Feedback?

UploadFile Method

Will upload a file to a folder.

Syntax

public String uploadFile(String fileName, String parentId);

Remarks

The method when called will upload a file specified in the LocalFile property. If SetUploadStream has been used to set an upload stream, it will take priority as the file data source. If LocalFile has not been set or a stream has not been set using SetUploadStream then the component 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 component will overwrite a file if a file is uploaded to the same folder with the same name.

If SetUploadStream has been used to set an upload stream, it will take priority as the file data source. 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 component uses the simple upload mechanism.

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

Resumable

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

When UseResumableUpload is set to true and UploadFile is called, a resumable upload session is started by the component. Once called and the component fragments the file, the ResumeURL property is populated. This URL needs to be set so that the component 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 component 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 component is used, they should already be populated, and no special action should be needed). If uploading from a stream, be sure to reset its position to where it was the first time the upload was started (typically the beginning). 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");

MemoryStream uploadStream = new MemoryStream(File.ReadAllBytes("../MyFile.zip"));
shareFile.UseResumableUpload = true;
shareFile.SetUploadStream(uploadStream);
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.
// You MUST reset the stream's position to where it was when you first started the upload!
uploadStream.Position = 0;
shareFile.UploadFile("MyFile.zip");

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