Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drive: FilesCreateCall.Media does not support file size #452

Open
dougreese opened this issue Feb 17, 2020 · 2 comments
Open

drive: FilesCreateCall.Media does not support file size #452

dougreese opened this issue Feb 17, 2020 · 2 comments
Labels
api: drive Issues related to the Drive API API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@dougreese
Copy link

dougreese commented Feb 17, 2020

In the v3 API, using Files.Create(...) with Media support does not allow for specifying total file size. As a result, the ProgressUpdater function supplied always receives a total value of 0.

Using ReusableMedia does support total size, but the doc states:

Deprecated: use Media instead.

The only way to calculate upload progress is to use the deprecated ReusableMedia support. The internally created MediaInfo does not expose the size value, and the only way to set it is via NewInfoFromReusableMedia, which is called by the FilesCreateCall.ReusableMedia method. FilesCreateCall.Media uses NewInfoFromMedia, and I don't see a way to specify size.

@yoshi-automation yoshi-automation added the triage me I really want to be triaged. label Feb 17, 2020
@tbpg tbpg changed the title FilesCreateCall.Media does not support file size drive: FilesCreateCall.Media does not support file size Feb 18, 2020
@tbpg tbpg added type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. and removed triage me I really want to be triaged. labels Feb 18, 2020
@tbpg
Copy link
Contributor

tbpg commented Feb 18, 2020

@asrivas, any thoughts on if we should expose this?

Perhaps @broady has ideas?

@du5
Copy link

du5 commented Jun 9, 2021

Try this.

f, _ := os.Open(*File)
info, _ := f.Stat()
total := FileSizeFormat(info.Size())

upf := srv.Files.Create(&drive.File{Name: info.Name()}).Media(f).ProgressUpdater(func(current, _ int64) {
	fmt.Printf("Uploaded %s/%s @ %.2f%%\r", FileSizeFormat(current), total, float64(current*100)/float64(info.Size()))
})
if _, err := upf.Do(); err == nil {
	log.Println("Done.")
} else {
	log.Println(err.Error())
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: drive Issues related to the Drive API API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

No branches or pull requests

5 participants