2012-04-18 71 views
3

我想上傳一個簡單的文本文件到谷歌文件中的特定文件夾,但沒有運氣。無法上傳到特定的文件夾得到503錯誤

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是錯誤的,但我不能找出正確的。

回答

2

有在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; 
    } 
    } 
} 
1

只要按照文章Google Apps Platform Uploading documents
還檢查了Google Documents List API version 3.0
開放的應該是類似下面:

string feed = @"https://developers.google.com/google-apps/documents-list/#getting_a_resource_entry_again"; 
//it may not be exact, just check and read from the links 
+0

你可以告訴我,如果飼料尿素是正確的嗎?我懷疑這是問題。 – 2012-04-18 19:28:49

+0

我不知道,錯誤503是服務不可用,http://www.checkupdown.com/status/E503.html – Habib 2012-04-18 19:30:56

+0

好吧,我真的很感謝你的幫助。請注意。 – 2012-04-18 19:34:57

1

試試這個uri:

"https://docs.google.com/feeds/default/private/full/folder%3A" + fRid + "/contents" 

// FRID是該文件夾的資源ID ..你的情況:0B2dzFB6YvN-kYTRlNmNhYjEtMTVmNC00ZThkLThiMjQtMzFhZmMzOGE2ZWU1

而且我猜你的URI是因爲你正在使用的文件夾資源ID作爲給這個錯誤 - 文件夾:RESOURCEID

嘗試刪除文件夾:,只使用RID

代碼,以切斷 「文件夾:」 -

int ridIndex = dRid.IndexOf(":"); 
Rid = Rid.Substring(ridIndex + 1); 
相關問題