我決定在我的WPF項目中使用Google驅動器api。我搜索了很多文檔和樣本。我學會了併成功了.Everyhing運行良好。我使用這個函數來插入/上傳。Google Drive Api .Net上傳錯誤
public static Google.Apis.Drive.v2.Data.File InsertFile(DriveService service, String title, String description, String parentId, String mimeType, String filename)
{
Google.Apis.Drive.v2.Data.File body = new Google.Apis.Drive.v2.Data.File();
body.Title = title;
body.Description = description;
body.MimeType = mimeType;
if (!String.IsNullOrEmpty(parentId))
{
body.Parents = new List<ParentReference>() { new ParentReference() { Id = parentId } };
}
byte[] byteArray = System.IO.File.ReadAllBytes(filename);
MemoryStream stream = new MemoryStream(byteArray);
try
{
FilesResource.InsertMediaUpload request = service.Files.Insert(body, stream, mimeType);
request.Upload();
Google.Apis.Drive.v2.Data.File file = request.ResponseBody;
return file;
}
catch (Exception e)
{
Console.WriteLine("An error occurred: " + e.Message);
}
}
當我想上傳一個小文件到谷歌驅動器,它的工作原理。但我選擇上傳大型文件,它提供了一個錯誤,並fails.I得到這個錯誤
System.Net.WebException was caught HResult=-2146233079 Message=The request was aborted: The request was canceled.Source=System StackTrace:
at System.Net.ConnectStream.InternalWrite(Boolean async, Byte[] buffer, Int32 offset, Int32 size, AsyncCallback callback, Object state)
at System.Net.ConnectStream.Write(Byte[] buffer, Int32 offset, Int32 size)
at Google.Apis.Upload.ResumableUpload`1.SendChunk(Stream stream, Uri uri, Int64 position)
at Google.Apis.Upload.ResumableUpload`1.Upload()
at Google.Apis.Util.Utilities.InsertFile(DriveService service, String title, String description, String parentId, String mimeType, String filename) in ..
我尋找這個錯誤,並滿足同樣的問題,但我不明白的地方,我wrong.Can任何人的幫助我或清楚地修復我的代碼。 謝謝:)
該文件有多大,上傳需要多長時間? –
我嘗試16mb,30mb大小的文件,它給出了一個錯誤。如果我想上傳小文件沒有關係。 – muhammedkasva
上傳時間是否超過1小時? –