AbdelrahmanAA / google-api-python-client

Automatically exported from code.google.com/p/google-api-python-client
Other
0 stars 0 forks source link

MediaIoBaseUpload gets size 0 for pipes #146

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago

What steps will reproduce the problem?
1. Create a python script with the following lines:

  from sys import stdin
  from apiclient.http import MediaIoBaseUpload
  print MediaIoBaseUpload(stdin, 'mimetype').size()

2. stdin from file works as expected
  $ python script.py < script.py
  117
but pipes get size 0 although data may be available
  $ echo 'abc' | python script.py
  0

What version of the product are you using? On what operating system?
I'm using a  mercurial repository synced to revision 444 in Ubuntu.

Please provide any additional information below.
The MediaIoBase constructor uses
  os.fstat(fileno).st_size
if it's available. Unless there's a good indicator of whether that value is 
trustworthy, perhaps we should only use it when it's non-zero.

Original issue reported on code.google.com by yova...@google.com on 13 Jun 2012 at 2:45

GoogleCodeExporter commented 8 years ago
MediaIoBaseBase needs a seekable stream and sys.stdin isn't seekable, so this 
wouldn't fix the issue.

Original comment by jcgregorio@google.com on 13 Jun 2012 at 5:32

GoogleCodeExporter commented 8 years ago
Sorry, I should have also noted that my modified MediaIoBaseUpload accepts an 
is_seekable argument that causes it to skip the self._fh.seek(begin) line if 
False. I'm not sure if this is something you would want to include as well. 
Alternatively, we could use a try-catch or other mechanism to determine if the 
object is seekable.

Original comment by yova...@google.com on 13 Jun 2012 at 5:39

GoogleCodeExporter commented 8 years ago
Seeking isn't optional, a chunk uploaded to the server may fail and the 
uploader will seek back to re-upload the data.

Original comment by jcgregorio@google.com on 13 Jun 2012 at 5:47

GoogleCodeExporter commented 8 years ago
Right. I'm probably looking for a chunked non-resumable upload. Should this be 
another distinct MediaUpload subclass? Do you think interest in such a subclass 
is sufficiently common to provide it with the Google API client?

Original comment by yova...@google.com on 13 Jun 2012 at 5:55

GoogleCodeExporter commented 8 years ago
CL out for review:  http://codereview.appspot.com/6300093/

Original comment by jcgregorio@google.com on 14 Jun 2012 at 6:57

GoogleCodeExporter commented 8 years ago
This issue was closed by revision 3ba72a5faf1a.

Original comment by jcgregorio@google.com on 15 Jun 2012 at 12:40