diff options
author | Nam T. Nguyen <namnguyen@google.com> | 2015-12-01 10:18:56 -0800 |
---|---|---|
committer | Nam T. Nguyen <namnguyen@google.com> | 2015-12-01 10:18:56 -0800 |
commit | dc13631485efcb8b9f533b9a55d4f98c50a3d37b (patch) | |
tree | 382a68c6a63bd19614b4d8d38632ed65b7850280 /googleapiclient | |
parent | dbabf825f6a5224a4bdcebd2390b21f7797f651d (diff) | |
download | google-api-python-client-dc13631485efcb8b9f533b9a55d4f98c50a3d37b.tar.gz |
Default to octet-stream if mimetype detection fails.
The function mimetypes.guess_type returns (None, None) if it fails to
find a matching extension. In that case, we should just treat the media
as application/octet-stream.
Diffstat (limited to 'googleapiclient')
-rw-r--r-- | googleapiclient/http.py | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/googleapiclient/http.py b/googleapiclient/http.py index 41daedcdf..10559c5e5 100644 --- a/googleapiclient/http.py +++ b/googleapiclient/http.py @@ -425,7 +425,11 @@ class MediaFileUpload(MediaIoBaseUpload): self._filename = filename fd = open(self._filename, 'rb') if mimetype is None: - (mimetype, encoding) = mimetypes.guess_type(filename) + # No mimetype provided, make a guess. + mimetype, _ = mimetypes.guess_type(filename) + if mimetype is None: + # Guess failed, use octet-stream. + mimetype = 'application/octet-stream' super(MediaFileUpload, self).__init__(fd, mimetype, chunksize=chunksize, resumable=resumable) |