2
我身邊讀了幾個問題,我想這些例子,他們的工作對我來說,這裏是鏈接: - Link 1 - Link 2 - Link 3C#谷歌阿比載流
然而, 我是什麼嘗試完成它有點不同,即時嘗試修改/上傳包含純文本里面的.DAT文件。我能夠毫無問題地閱讀文件內容,但我總是得到400錯誤請求(協議錯誤)。繼承人我的代碼。
DocumentsService service = new DocumentsService("Man");
service.setUserCredentials(UserName, Passwod);
DocumentsListQuery fileQuery = new DocumentsListQuery();
fileQuery.Query = User.FileName;
fileQuery.TitleExact = true;
DocumentsFeed feed = service.Query(fileQuery);
//Here I get my file to update
DocumentEntry entry = (DocumentEntry)feed.Entries[0];
// Set the media source
//Here I have tried application/octet-stream also
entry.MediaSource = new MediaFileSource(DataStream, User.FileName, text/plain");
// 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 syncOperationProgressEventHandler(OnProgress);
ClientLoginAuthenticator authenticator = new ClientLoginAuthenticator("Man", ServiceNames.Documents,Credentials);
Uri updateUploadUrl = new Uri(UploadUrl);
AtomLink aLink = new AtomLink(updateUploadUrl.AbsoluteUri);
aLink.Rel = ResumableUploader.CreateMediaRelation;
entry.Links.Add(aLink);
// Start the update process.
uploader.UpdateAsync(authenticator,entry,new object());
謝謝。
編輯: 這就是我解決它的方法。感謝克勞迪奧爲指導我在正確的方向
- 下載應用實例來源:Download Sample (.zip)
- 實現從SampleHelper項目,這些項目中:AuthorizationMgr,INativeAuthorizationFlow,LoopbackServerAuthorizationFlow,WindowTitleNativeAuthorizationFlow
使用此代碼:
//Call Authorization method... (omitted) File body = new File(); body.Title = title; body.Description = description; body.MimeType = mimeType; byte[] byteArray = System.IO.File.ReadAllBytes(filename); MemoryStream stream = new MemoryStream(byteArray); try { FilesResource.InsertMediaUpload request = service.Files.Insert(body, stream, mimeType); request.Upload(); File file = request.ResponseBody; // Uncomment the following line to print the File ID. // Console.WriteLine("File ID: " + file.Id); return file; } catch (Exception e) { Console.WriteLine("An error occurred: " + e.Message); return null; }
你知道或雲端的WinForms的例子... – w0rtez
該庫包括了一個WinForms樣本任務API(http://code.google.com/p/google-api-dotnet-client/source/browse?repo=samples#hg%2FTasks.WinForms.NoteMgr),不應該很難將它與我送你的Drive樣品 –
好的。謝謝,我會檢查出來,並讓你知道... – w0rtez