@@ -370,7 +370,8 @@ def upload_from_file(self, file_obj, rewind=False, size=None,
370370 :type size: int
371371 :param size: The number of bytes to read from the file handle.
372372 If not provided, we'll try to guess the size using
373- :func:`os.fstat`
373+ :func:`os.fstat`. (If the file handle is not from the
374+ filesystem this won't be possible.)
374375
375376 :type content_type: string or ``NoneType``
376377 :param content_type: Optional type of content being uploaded.
@@ -382,6 +383,9 @@ def upload_from_file(self, file_obj, rewind=False, size=None,
382383 ``NoneType``
383384 :param connection: Optional. The connection to use when sending
384385 requests. If not provided, falls back to default.
386+
387+ :raises: :class:`ValueError` if size is not passed in and can not be
388+ determined
385389 """
386390 connection = _require_connection (connection )
387391 content_type = (content_type or self ._properties .get ('contentType' ) or
@@ -392,7 +396,13 @@ def upload_from_file(self, file_obj, rewind=False, size=None,
392396 file_obj .seek (0 , os .SEEK_SET )
393397
394398 # Get the basic stats about the file.
395- total_bytes = size or os .fstat (file_obj .fileno ()).st_size
399+ total_bytes = size
400+ if total_bytes is None :
401+ if hasattr (file_obj , 'fileno' ):
402+ total_bytes = os .fstat (file_obj .fileno ()).st_size
403+ else :
404+ raise ValueError ('total bytes could not be determined. Please '
405+ 'pass an explicit size.' )
396406 headers = {
397407 'Accept' : 'application/json' ,
398408 'Accept-Encoding' : 'gzip, deflate' ,
0 commit comments