liuqiaosz / google-api-dotnet-client

Automatically exported from code.google.com/p/google-api-dotnet-client
Apache License 2.0
0 stars 0 forks source link

NullReferenceException in ResumableUpload.Uplod #261

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Steps to reproduce:
1. Create an insert request with 
"Google.Apis.Drive.v2.FilesResource.InsertMediaUpload 
Insert(Google.Apis.Drive.v2.Data.File body, System.IO.Stream stream, string 
contentType)", size of uploaded file should be more than about 20MB.
2. Let ChunkSize 0 value.
3. Invoke "Upload()"

Expected result: If I put some invalid parameters, I expect get a message with 
error description.
Actual result: In the code
catch (WebException we)
            {
                var responseStream = we.Response.GetResponseStream();
                if (responseStream == null)
                    throw;
we.Response is null. As a result I get NullReferenceException, no message about 
a cause of the issue.

Original issue reported on code.google.com by passm...@gmail.com on 23 Sep 2012 at 9:31

GoogleCodeExporter commented 9 years ago
Stable Release '20120921-1.2.4647-beta'
21 September 2012

Original comment by passm...@gmail.com on 23 Sep 2012 at 9:33

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Please check if we.Response is null and throw a "friendly" exception.

Original comment by passm...@gmail.com on 4 Oct 2012 at 10:48

GoogleCodeExporter commented 9 years ago
I have chunk size, but also get NullReferenceException when try upload file, 
how to fix it?

Original comment by name....@gmail.com on 4 Oct 2012 at 10:55

GoogleCodeExporter commented 9 years ago
I use chunk size 1024*1024 as a workaround.

Original comment by passm...@gmail.com on 4 Oct 2012 at 10:58

GoogleCodeExporter commented 9 years ago
here my code
    Google.Apis.Drive.v2.Data.File body = new Google.Apis.Drive.v2.Data.File();
    body.Title = "test1.jpg";
    body.Description = "";
    body.MimeType = mimeType;

    var request = service.Files.Insert(body, stream, mimeType);
    ((MainForm)Application.OpenForms[0]).progressBar1.Maximum = (int)stream.Length;
    request.ProgressChanged += new Action<Google.Apis.Upload.IUploadProgress>(request_ProgressChanged);
    request.Upload();
    return request.ResponseBody;
I need manually set chunkSize?

Original comment by name....@gmail.com on 4 Oct 2012 at 11:02

GoogleCodeExporter commented 9 years ago
My current chunkSize is 0x00a00000

Original comment by name....@gmail.com on 4 Oct 2012 at 11:02

GoogleCodeExporter commented 9 years ago
Yes, I set it manually.

request = service.Files.Insert(body, fileStream, body.MimeType);
request.ChunkSize = ChunkSize; //1024*1024

Original comment by passm...@gmail.com on 4 Oct 2012 at 11:06

GoogleCodeExporter commented 9 years ago
chunk size 1024*1024 not working also

Original comment by name....@gmail.com on 4 Oct 2012 at 11:06

GoogleCodeExporter commented 9 years ago
It throws NullReference exception in catch {...}?

Original comment by passm...@gmail.com on 4 Oct 2012 at 11:08

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
After 50 seconds call Upload(), get NullReference with this stacktrace:
   в Google.Apis.Upload.ResumableUpload`1.Upload() в z:\google-api\google-api-dotnet-client\9-21-2012\default\Src\GoogleApis\Apis\Upload\ResumableUpload.cs:строка 306
   в WinGrab2012.Utils.UploadFile(DriveService service, String fileName, Stream stream, String mimeType) в C:\Users\V10\Documents\Visual Studio 2010\Projects\WinGrab2012\Utils.cs:строка 294

Original comment by name....@gmail.com on 4 Oct 2012 at 11:19

GoogleCodeExporter commented 9 years ago
Yes, the same code throws the exception.
I'm not a developer of this code. But workaround with ChunkSize works for me.

The last tip: try to check this issue with a very small file.

Original comment by passm...@gmail.com on 4 Oct 2012 at 11:26

GoogleCodeExporter commented 9 years ago
I found fix for it:
stream.Position = 0; 

Original comment by name....@gmail.com on 4 Oct 2012 at 11:38

GoogleCodeExporter commented 9 years ago
before call Upload()

Original comment by name....@gmail.com on 4 Oct 2012 at 11:38

GoogleCodeExporter commented 9 years ago
Full code:
    stream.Position = 0;
    var request = service.Files.Insert(body, stream, mimeType);
    request.Upload();

Original comment by name....@gmail.com on 4 Oct 2012 at 11:40

GoogleCodeExporter commented 9 years ago
May be.
I've just checked with default chunk size. It works now on my side :)
Anyway I think this catch section should be updated.

Original comment by passm...@gmail.com on 4 Oct 2012 at 11:50

GoogleCodeExporter commented 9 years ago
yea

Original comment by name....@gmail.com on 4 Oct 2012 at 12:10

GoogleCodeExporter commented 9 years ago
Thanks for reporting this I am working on a change that will fix this see 
https://codereview.appspot.com/6620056/

David.

Original comment by davidwat...@google.com on 5 Oct 2012 at 3:23

GoogleCodeExporter commented 9 years ago
Thanks for pointing this out, I have improved the code in this area and checked 
in the fix. 

This fix will be in the next release, currently scheduled for Friday 12th 
October.

Original comment by davidwat...@google.com on 5 Oct 2012 at 5:10

GoogleCodeExporter commented 9 years ago
Thank you!

Original comment by passm...@gmail.com on 5 Oct 2012 at 5:11

GoogleCodeExporter commented 9 years ago
This is now released.

Original comment by davidwat...@google.com on 11 Oct 2012 at 5:15