Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 有没有办法从远程url-C上传文件到谷歌硬盘#_C#_.net_Google Drive Api_Google Api Dotnet Client - Fatal编程技术网

C# 有没有办法从远程url-C上传文件到谷歌硬盘#

C# 有没有办法从远程url-C上传文件到谷歌硬盘#,c#,.net,google-drive-api,google-api-dotnet-client,C#,.net,Google Drive Api,Google Api Dotnet Client,基本上,我有一些远程服务器上的视频,我想上传到谷歌驱动器,而不下载到客户端。直接上传到谷歌驱动。我读了stackoverflow的文章和一些问题,但他们没有提到任何类似的内容。至少在我读到的问题中。我在.net framework windows窗体应用程序上执行此操作。要使上载工作正常,您需要在运行代码的计算机上安装文件。你必须先把它们下载到自己的电脑上,然后再上传到谷歌硬盘上 { // Create the service using the client credentials.

基本上,我有一些远程服务器上的视频,我想上传到谷歌驱动器,而不下载到客户端。直接上传到谷歌驱动。我读了stackoverflow的文章和一些问题,但他们没有提到任何类似的内容。至少在我读到的问题中。我在.net framework windows窗体应用程序上执行此操作。

要使上载工作正常,您需要在运行代码的计算机上安装文件。你必须先把它们下载到自己的电脑上,然后再上传到谷歌硬盘上

{
    // Create the service using the client credentials.
    var service = new DriveService(new BaseClientService.Initializer()
        {
            HttpClientInitializer = credential,
            ApplicationName = "APP_NAME_HERE"
        });
    var uploadStream = new System.IO.FileStream("FILE_NAME",
                                                System.IO.FileMode.Open,
                                                System.IO.FileAccess.Read);
    // Get the media upload request object.
    InsertMediaUpload insertRequest = service.Files.Insert(
        new File
        {
            Title = "FILE_TITLE",
        },
        uploadStream,
        "image/jpeg");

    // Add handlers which will be notified on progress changes and upload completion.
    // Notification of progress changed will be invoked when the upload was started,
    // on each upload chunk, and on success or failure.
    insertRequest.ProgressChanged += Upload_ProgressChanged;
    insertRequest.ResponseReceived += Upload_ResponseReceived;

    var task = insert.UploadAsync();
    task.ContinueWith(t =>
        {
            // Remeber to clean the stream.
            uploadStream.Dispose();
        });
}

static void Upload_ProgressChanged(IUploadProgress progress)
{
    Console.WriteLine(progress.Status + " " + progress.BytesSent);
}

static void Upload_ResponseReceived(File file)
{
    Console.WriteLine(file.Title + " was uploaded successfully");
}

为了使上传工作正常,您需要在运行代码的机器上安装该文件。你必须先把它们下载到自己的电脑上,然后再上传到谷歌硬盘上

{
    // Create the service using the client credentials.
    var service = new DriveService(new BaseClientService.Initializer()
        {
            HttpClientInitializer = credential,
            ApplicationName = "APP_NAME_HERE"
        });
    var uploadStream = new System.IO.FileStream("FILE_NAME",
                                                System.IO.FileMode.Open,
                                                System.IO.FileAccess.Read);
    // Get the media upload request object.
    InsertMediaUpload insertRequest = service.Files.Insert(
        new File
        {
            Title = "FILE_TITLE",
        },
        uploadStream,
        "image/jpeg");

    // Add handlers which will be notified on progress changes and upload completion.
    // Notification of progress changed will be invoked when the upload was started,
    // on each upload chunk, and on success or failure.
    insertRequest.ProgressChanged += Upload_ProgressChanged;
    insertRequest.ResponseReceived += Upload_ResponseReceived;

    var task = insert.UploadAsync();
    task.ContinueWith(t =>
        {
            // Remeber to clean the stream.
            uploadStream.Dispose();
        });
}

static void Upload_ProgressChanged(IUploadProgress progress)
{
    Console.WriteLine(progress.Status + " " + progress.BytesSent);
}

static void Upload_ResponseReceived(File file)
{
    Console.WriteLine(file.Title + " was uploaded successfully");
}

嗨,你能展示一下你的代码示例吗?我还没有开始使用谷歌硬盘的代码。我首先看到我想要的东西是否可能,因为如果不可能,我可能不会使用google drive。嗨,你能展示一下你的代码示例吗?我还没有开始使用google drive代码。我首先看到我想要的东西是否可能,因为如果不可能,我可能不会使用谷歌硬盘。