Discuss this help topic in SecureBlackbox Forum
Clouds: Write data to existing file
To write the data into the existing file
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.