编程语言
首页 > 编程语言> > C#-无法上传到特定文件夹,但出现503错误

C#-无法上传到特定文件夹,但出现503错误

作者:互联网

我正在尝试将简单的文本文件上传到Google文档中的特定文件夹,但是没有运气.

FileStream fileStream = new FileStream(@"c:\test.txt", System.IO.FileMode.Open);
DocumentEntry lastUploadEntry = 
    globalData.service.UploadDocument("c:\\test.txt", null);                                                                               

string feed =
    "https://docs.google.com/feeds/upload/create-session/default/private/full/folder%folder:0B2dzFB6YvN-kYTRlNmNhYjEtMTVmNC00ZThkLThiMjQtMzFhZmMzOGE2ZWU1/contents/";

var result = 
    globalData.service.Insert(new Uri(feed), fileStream, "application/pdf", "test");

我说错了

“The remote server returned an error: (503) Server Unavailable.”

我怀疑目标文件夹uri错误,但是我找不到正确的文件夹.

解决方法:

https://developers.google.com/google-apps/documents-list/#uploading_a_new_document_or_file_with_both_metadata_and_content处有一个完整的示例使用了可恢复的上载组件:

using System;
using Google.GData.Client;
using Google.GData.Client.ResumableUpload;
using Google.GData.Documents;

namespace MyDocumentsListIntegration
{
  class Program
  {
    static void Main(string[] args)
    {
      DocumentsService service = new DocumentsService("MyDocumentsListIntegration-v1");

      // TODO: Instantiate an Authenticator object according to your authentication
      // mechanism (e.g. OAuth2Authenticator).
      // Authenticator authenticator =  ...

      // Instantiate a DocumentEntry object to be inserted.
      DocumentEntry entry = new DocumentEntry();

      // Set the document title
      entry.Title.Text = "Legal Contract";

      // Set the media source
      entry.MediaSource = new MediaFileSource("c:\\contract.txt", "text/plain");

      // Define the resumable upload link
      Uri createUploadUrl = new Uri("https://docs.google.com/feeds/upload/create-session/default/private/full");
      AtomLink link = new AtomLink(createUploadUrl.AbsoluteUri);
      link.Rel = ResumableUploader.CreateMediaRelation;
      entry.Links.Add(link);

      // Set the service to be used to parse the returned entry
      entry.Service = service;

      // Instantiate the ResumableUploader component.
      ResumableUploader uploader = new ResumableUploader();

      // Set the handlers for the completion and progress events
      uploader.AsyncOperationCompleted += new AsyncOperationCompletedEventHandler(OnDone);
      uploader.AsyncOperationProgress += new AsyncOperationProgressEventHandler(OnProgress);

      // Start the upload process
      uploader.InsertAsync(authenticator, entry, new object());
    }

    static void OnDone(object sender, AsyncOperationCompletedEventArgs e) {
        DocumentEntry entry = e.Entry as DocumentEntry;
    }

    static void OnProgress(object sender, AsyncOperationProgressEventArgs e) {
        int percentage = e.ProgressPercentage;
    }
  }
}

标签:google-docs,google-docs-api,c
来源: https://codeday.me/bug/20191101/1983591.html