gpt4 book ai didi

c# - 无法上传到特定文件夹并出现 503 错误

转载 作者:行者123 更新时间:2023-11-30 15:39:35 25 4
gpt4 key购买 nike

我正在尝试将一个简单的文本文件上传到 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;
}
}
}

关于c# - 无法上传到特定文件夹并出现 503 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10216190/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com