-1

So the story is that I'm writing a file manager with two panels (just like Total Commander has). I'm trying to integrate the 3 main cloud providers (GDrive, Dropbox, OneDrive) into it. I'm writing this file manager in C# (WPF) and trying to use the official SDKs. One of the features is that you can copy files and folders from one cloud to another one, so like GDrive is on the left panel and Dropbox on the right panel and copying from GDrive to Dropbox.

One solution could be that the program downloads that file from one cloud temporarily to the client's machine, and then uploads from there to the other one. But I'd rather not use this for multiple reasons.

So I'm thinking about chunking up the file into several parts during download(like into 5MB parts), keep it in the memory just until I upload that chunk to the other cloud. In this way, I wouldn't use the client's machine to store that file (except for that 5MB part of course).

Is there any way to achieve this?

  • I don*t know the apis of the different cloud providers, but if the api give you a stream for download/upload it should be possible: Initialize Upload and download to get the streams, read 5 MB from download stream, write the 5 MB into upload stream and so on. Ofcourse you have to check for file completed (the last read will be lesser than 5 MB) – H.G. Sandhagen May 21 '19 at 18:22
  • “Is there a way?” [is a poor question](https://softwareengineering.meta.stackexchange.com/questions/7273/). – Dour High Arch May 21 '19 at 18:36
  • Nevermind, looks like I have to use this solution: https://stackoverflow.com/questions/45663027/resuming-interrupted-upload-using-google-drive-v3-c-sharp-sdk – joelzimmer May 22 '19 at 07:37
  • Could you please share the sample you had created which transfer files to clouds? – Laxmi Lal Menaria May 02 '22 at 05:23

1 Answers1

0

Here is code to download files from GDrive. You notice it uses a stream. You can just use the this stream object to feed the stream object for the upload. There are similar examples for the other drive if you search.

    using Google.Apis.Authentication;
    using Google.Apis.Drive.v2;
    using Google.Apis.Drive.v2.Data;

    using System.Net;

    public class DownLoadFromGDrive{

      /// <param name="authenticator">
      /// Authenticator responsible for creating authorized web requests.
      /// </param>
      /// <param name="file">Drive File instance.</param>
      /// <returns>File's content if successful, null otherwise.</returns>

      public static System.IO.Stream DownloadFile(
          IAuthenticator authenticator, File file) {
        if (!String.IsNullOrEmpty(file.DownloadUrl)) {
          try {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(
                new Uri(file.DownloadUrl));
            authenticator.ApplyAuthenticationToRequest(request);
            HttpWebResponse response = (HttpWebResponse) request.GetResponse();
            if (response.StatusCode == HttpStatusCode.OK) {
              return response.GetResponseStream();
            } 
            else 
           {
              return null;
            }
          } 
          catch (Exception e) 
          {
            return null;
          }
        } 
      }
    }

This link explains how to upload to GDrive:

Edney Holder
  • 1,140
  • 8
  • 22
  • @joelzimmer I cannot get to the API reference from work, but my guess is that it should be very close to the same if not the same process. – Edney Holder May 21 '19 at 21:10