aboutsummaryrefslogtreecommitdiff
path: root/googleapiclient
diff options
context:
space:
mode:
authorNam T. Nguyen <namnguyen@google.com>2015-12-01 10:18:56 -0800
committerNam T. Nguyen <namnguyen@google.com>2015-12-01 10:18:56 -0800
commitdc13631485efcb8b9f533b9a55d4f98c50a3d37b (patch)
tree382a68c6a63bd19614b4d8d38632ed65b7850280 /googleapiclient
parentdbabf825f6a5224a4bdcebd2390b21f7797f651d (diff)
downloadgoogle-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.py6
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)