Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/8.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# 如何在C中通过FileStream和ResumableUploader上传/更新文件#_C#_Filestream_Gdata_Google Docs Api_Google Drive Api - Fatal编程技术网

C# 如何在C中通过FileStream和ResumableUploader上传/更新文件#

C# 如何在C中通过FileStream和ResumableUploader上传/更新文件#,c#,filestream,gdata,google-docs-api,google-drive-api,C#,Filestream,Gdata,Google Docs Api,Google Drive Api,我想通过Google文档列表API(C#)中的System.IO.FileStream上传/更新文件? 我在下面使用两种方法:Google.GData.Client.ResumableUpload.ResumableUploader (1) public void UpdateAsync(身份验证程序身份验证、AbstractEntry有效负载、对象用户数据) (2) public void UpdateAsync(验证器身份验证、Uri resumableUploadUri、流负载、字符串内

我想通过Google文档列表API(C#)中的System.IO.FileStream上传/更新文件?

我在下面使用两种方法:Google.GData.Client.ResumableUpload.ResumableUploader
(1) public void UpdateAsync(身份验证程序身份验证、AbstractEntry有效负载、对象用户数据)
(2) public void UpdateAsync(验证器身份验证、Uri resumableUploadUri、流负载、字符串内容类型、对象用户数据)

(1) 成功。
(2) 失败,403禁止或其他…

那么,有人有关于(2)的示例代码吗?

我的代码为(2): 此代码由Claudio Cherubino的示例代码编辑,用于将文件流上载到Google文档(驱动器)。但该文件(DocumentEntry)的名称在谷歌硬盘的页面上显示为“未命名”。“鼻涕虫”似乎不起作用。我是否错过了一些重要的设置

Google.GData.Documents.DocumentsService conn =
new Google.GData.Documents.DocumentsService("TestSend");
conn.setUserCredentials("UserName", "UserPass");

string path = @"D:\test_file\test.exe"; 

Google.GData.Client.ResumableUpload.ResumableUploader send =
new Google.GData.Client.ResumableUpload.ResumableUploader();
send.AsyncOperationCompleted += new Google.GData.Client.AsyncOperationCompletedEventHandler(
    delegate(object sender,
        Google.GData.Client.AsyncOperationCompletedEventArgs e)
    {
        System.Windows.Forms.MessageBox.Show("File Send Done");
    }
);

System.IO.FileStream fs = new System.IO.FileStream(path, System.IO.FileMode.Open, System.IO.FileAccess.ReadWrite);

send.InsertAsync(
    new Google.GData.Client.ClientLoginAuthenticator("TestSend", "writely", this._DiskConn.Credentials),
    new System.Uri("https://docs.google.com/feeds/upload/create-session/default/private/full?v=3"),
    fs,
    "application/octet-stream",
    System.IO.Path.GetFileName(path),
    new object()
);

请尝试以下代码:

DocumentsService service = new DocumentsService("MyDocumentsListIntegration-v1");
ClientLoginAuthenticator authenticator = new ClientLoginAuthenticator(APPLICATION_NAME, ServiceNames.Documents, USERNAME, PASSWORD);

string slug = "Legal contract";
MediaFileSource mediaSource = new MediaFileSource("c:\\contract.txt", "text/plain");
Uri createUploadUrl = new Uri("https://docs.google.com/feeds/upload/create-session/default/private/full?v=3");

ResumableUploader ru = new ResumableUploader();
ru.InsertAsync(authenticator, createUploadUrl, mediaSource.GetDataStream(), mediaSource.ContentType, slug, new object());

这是工作!我将“mediaSource.GetDataStream()”替换为“newfilestream(“[file path]”,FileMode.Open)”,并在Google Drive上找到了该文件。但有点奇怪,谷歌硬盘中名为“Untitled”的文档条目,slug无法正常工作。我用我的新代码上传我的帖子。