Google-api-dotnet-client: Upload fails on files larger than ChunkSize (UWP)

Created on 4 Dec 2017  路  6Comments  路  Source: googleapis/google-api-dotnet-client

I use google Api with UWP project
Nugets(Google.Apis 1.31.0-beta01, Google.Apis.Auth 1.31.0-beta01, Google.Apis.Drive.v3 1.30.0.1044) were installed.

I try upload file on google drive.

public async UploadAsync(string parentId, string fileName, IStorageFile inputFile, CancellationToken ct) 
{
    var body = new Google.Apis.Drive.v3.Data.File() {
        Name = fileName,
        Parents = new List<string>() { parentId }
    };
    using (var streamFile = await inputFile.OpenReadAsync()) {
        using (var stream = streamFile.AsStreamForRead()) {
            stream.Position = 0;
            var uploadRequest = _driveService.Files.Create(body, stream, inputFile.ContentType);
            uploadRequest.Fields = "id, name";
            uploadRequest.ProgressChanged += (obj) =>
            {
                    Debug.WriteLine($"sent - {obj.BytesSent}");
            };
            await uploadRequest.UploadAsync(ct);

            var file = uploadRequest.ResponseBody;
            Debug.WriteLine($"file - {file.Id}, {file.Name}");
        }
    }
}

I can only upload files < 10MB (by default). For large files(>10MB) UploadAsync doesn't finish and obj.BytesSent always 0.

When I change uploadRequest.ChunkSize the upload limit also changes.

p2+ bug

All 6 comments

I do something very like this for Storage all the time, and it's fine - certainly from console apps.

Are you able to reproduce this issue with a console app, or does it only happen in UWP? Are any exceptions thrown, or does the task just never complete?

I don't try console apps and exceptions aren't thrown. Task can be cancelled by CancellationToken.

p.s. Download works with large files

Could you try a console app using the same code as far as you can? Knowing whether this is a UWP-specific issue or not would be a great first step.

Console app can upload file(>10MB) successfully. The code is the same with a small difference in getting the stream.

Console app code:

string filePath;
using (var stream = new System.IO.FileStream(filePath, System.IO.FileMode.Open))

UWP app code:

IStorageFile inputFile;
using (var streamFile = await inputFile.OpenReadAsync()) {
    using (var stream = streamFile.AsStreamForRead())
...

p.s. I use the same nugets (Google.Apis 1.31.0-beta01, Google.Apis.Auth 1.31.0-beta01, Google.Apis.Drive.v3 1.30.0.1044)

Okay, so this is only a problem on UWP. At the moment, UWP is an unsupported platform, but we are working on UWP support - so we'll need to make sure this works at that point too.

10MB is the size at which the upload uses multiple chunks, so presumably the problem is somewhere there.

Closing as UWP is an unsupported platform. Will re-open and investigate if we add support for UWP.

Was this page helpful?
0 / 5 - 0 ratings