IPWorks Cloud 2020 Delphi Edition

Questions / Feedback?

UploadFile Method

Uploads a new file resource.

function UploadFile(FileName: String): String;

Remarks

This method uploads a new file resource, with the given FileName (which should include a file extension), to the folder resource currently selected by RemoteId or RemotePath. The Id of the newly-created file resource is returned.

If the ClientCreatedTime and/or ClientModifiedTime configuration settings are non-empty when this method is called, the corresponding timestamps will be submitted with the file upload request.

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 ResourceData will be used.

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

Upload Notes

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

onedrive.LocalFile = "../MyFile.zip";
onedrive.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. 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 component. ResumeURL is populated with a URL identifying the session (this value may be needed for additional operations if the upload does not complete normally).

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. PollUploadStatus may be used to check the status of a resumable upload, including when it will expire (which is stored in the UploadExpDate configuration setting). An interrupted upload can be aborted explicitly using the AbortUpload method.

onedrive.LocalFile = "../MyFile.zip";
onedrive.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.
onedrive.UploadFile("MyFile.zip");

MemoryStream uploadStream = new MemoryStream(File.ReadAllBytes("../MyFile.zip"));
onedrive.SetUploadStream(uploadStream);
onedrive.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;
onedrive.UploadFile("MyFile.zip");

Name Conflict Resolution

If the desired FileName is already in use, the server's name conflict resolution behavior will follow these steps:
  1. If the RenameIfExists configuration setting is enabled, the server will modify the name of the new file resource to be unique. Refer to the RenameIfExists configuration setting for more information.
  2. Otherwise, if the Overwrite property is enabled, the server will replace the existing file resource with the newly-uploaded one.
  3. Otherwise, the server will return an error.

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