Discuss this help topic in SecureBlackbox Forum

Clouds: Write data to existing file

To write the data into the existing file

  1. Obtain the TElGoogleDriveFile object of the exising file which will be updated/overwritten.
  2. Call TElGoogleDriveFile.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 TElGoogleDriveFolder or cloned TElGoogleDriveFolder, remember to use TElGoogleDriveFolder.Release() method after the upload is complete.
  4. Important: use TElGoogleDriveFile.Release() method on the file object to complete file uploading.

C#:


TElGoogleDriveFile file = folder.CreateObject("uploaded.bin",
    String.Empty, String.Empty, false, false, false, null) as TElGoogleDriveFile;
try
{
    FileStream source = new FileStream(@"...", FileMode.Open, FileAccess.Read);
    try
    {
        file.Write(source);
    }
    finally
    {
        source.Close();
    }
}
finally
{
   file.Release();
}

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

Google Drive 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 TElGoogleDriveDataStorage.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 TElGoogleDriveDataStorage.ChunkedUploadChunkSize property. So, if the connection is broken, only data from the last chunk is lost. Just call TElGoogleDriveFile.Write() method again and uploading will be resumed automatically.

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

How To articles about Google Drive cloud

Discuss this help topic in SecureBlackbox Forum