def FromFile(cls, filename, mime_type=None, auto_transfer=True,
                 gzip_encoded=False, **kwds):
        """Create a new Upload object from a filename."""
        path = os.path.expanduser(filename)
        if not os.path.exists(path):
            raise exceptions.NotFoundError('Could not find file %s' % path)
        if not mime_type:
            mime_type, _ = mimetypes.guess_type(path)
            if mime_type is None:
                raise exceptions.InvalidUserInputError(
                    'Could not guess mime type for %s' % path)
        size = os.stat(path).st_size
        return cls(open(path, 'rb'), mime_type, total_size=size,
                   close_stream=True, auto_transfer=auto_transfer,
                   gzip_encoded=gzip_encoded, **kwds)
def FromFile ( cls , filename , mime_type = None , auto_transfer = True , gzip_encoded = False , ** kwds ) : path = os . path . expanduser ( filename ) if not os . path . exists ( path ) : raise exceptions . NotFoundError ( 'Could not find file %s' % path ) if not mime_type : mime_type , _ = mimetypes . guess_type ( path ) if mime_type is None : raise exceptions . InvalidUserInputError ( 'Could not guess mime type for %s' % path ) size = os . stat ( path ) . st_size return cls ( open ( path , 'rb' ) , mime_type , total_size = size , close_stream = True , auto_transfer = auto_transfer , gzip_encoded = gzip_encoded , ** kwds )
Create a new Upload object from a filename.