2012-06-09 1 views
0

Google 문서 목록 API (C#)에서 System.IO.FileStream으로 파일을 업로드/업데이트하고 싶습니까?

I 아래 양방향 사용 Google.GData.Client.ResumableUpload.ResumableUploader
(1) 공개 무효 UpdateAsync (인증 자 인증 AbstractEntry 페이로드, userData에 개체)
(2) 공공 무효 UpdateAsync (인증 자 인증, URI를 resumableUploadUri, 스트림 페이로드, 문자열 contentType, 객체 userData)

(1) 성공.
(2) 403 금지되었거나 다른 ...

그래서 (2)에 대한 샘플 코드가 있습니까?
C#의 FileStream 및 ResumableUploader로 파일을 업로드/업데이트하는 방법

에 대한 나의 코드 (2) :이 코드는 클라우디오 Cherubino에서 샘플 코드에 의해 편집하고, 구글 문서 도구 (드라이브)에 파일 스트림을 업로드하기위한 작업이다됩니다 . 하지만 파일 (DocumentEntry)의 이름은 Google 드라이브 페이지에 '제목 없음'으로 표시됩니다. 그것은 '슬러그'가 작동하지 않는 것 같습니다. 몇 가지 중요한 설정을 놓치고 있습니까?

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() 
); 

답변

0

다음 코드를보십시오 :

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()); 
+0

그것은 작품입니다! 'mediaSource.GetDataStream()'을 '새 FileStream ("[파일 경로]", FileMode.Open)'로 바꾼 다음 Google 드라이브에 파일을 찾았습니다. 그러나 조금 이상한 DocumentEntry라는 제목의 'Untitled'는 Google 드라이브에서 정상적으로 작동하지 않습니다. 내 새 코드로 내 게시물을 업로드합니다. – user1446337

관련 문제