Discuss this help topic in SecureBlackbox Forum

Clouds: Write data to existing file

To write the data into the existing file

  1. Obtain the TElOneDriveFile object of the exising file which will be updated/overwritten.
  2. Call TElOneDriveFile.Write() method of the above object, and pass it the stream, the data from which are to be placed to the file. If no security features (encryption and/or integrity protection) are going to be applied to this file, pass nil/null as the last parameter.
  3. If you used AcquireObject() method to obtain an instance of TElOneDriveFolder or cloned TElOneDriveFolder, remember to use TElOneDriveFolder.Release() method after the upload is complete.

C#:


TElOneDriveFile file = folder.CreateObject("uploaded.bin", true);
try
{
    FileStream source = new FileStream(@"...", FileMode.Open, FileAccess.Read);
    try
    {
        file.Write(source);
    }
    finally
    {
        source.Close();
    }
}
finally
{
    file.Release();
}

TElOneDriveDataStorage class has OnProgress event, which allows to track and show the progress of data upload, and interrupt the transfer if necessary.

If the data being uploaded to the server are to be encrypted or signed, you need to take certain additional steps.

OneDrive provides two methods for data uploading. The first one uploads data to the server as a single piece. So, if the connection is broken for any reason before all the data is transferred, the uploaded data is lost and has to be reuploaded again completely.

Such method is not effective for uploading large files, thus for files greater than specified in the TElOneDriveDataStorage.ChunkedUploadThreshold property another method, called "chunked upload", is used. Using this method data is uploaded to the server chunk-by-chunk. The chunk size is specified in the TElOneDriveDataStorage.ChunkedUploadChunkSize property. So, if the connection is broken, only data from the last chunk is lost. Just call TElOneDriveFile.Write() method again and uploading will be resumed automatically. If you need to cancel incomplete upload, use TElOneDriveFile.CancelUpload() method.

Unfortunately, OneDrive doesn't allow to write only a part of file, that's why the TElOneDriveDataStorage.WriteBlock() method throws an "unsupported operation" exception.

How To articles about OneDrive cloud

Discuss this help topic in SecureBlackbox Forum