def from_file(self, filename):
        """ Uploads a file from a filename on your system.

        :param filename: Path to file on your system.

        Example:
            >>> myimage.from_file('/path/to/dinner.png')
        """

        mimetype = mimetypes.guess_type(filename)[0] or "application/octal-stream"
        headers = {
            "Content-Type": mimetype,
            "Content-Length": str(os.path.getsize(filename)),
        }

        # upload file
        file_data = self._pump.request(
            "/api/user/{0}/uploads".format(self._pump.client.nickname),
            method="POST",
            data=open(filename, "rb").read(),
            headers=headers,
        )

        # now post it to the feed
        data = {
            "verb": "post",
            "object": file_data,
        }
        data.update(self.serialize())

        if not self.content and not self.display_name and not self.license:
            self._post_activity(data)
        else:
            self._post_activity(data, unserialize=False)

            # update post with display_name and content
            if self.content:
                file_data['content'] = self.content
            if self.display_name:
                file_data['displayName'] = self.display_name
            if self.license:
                file_data['license'] = self.license
            data = {
                "verb": "update",
                "object": file_data,
            }
            self._post_activity(data)

        return self
def from_file ( self , filename ) : mimetype = mimetypes . guess_type ( filename ) [ 0 ] or "application/octal-stream" headers = { "Content-Type" : mimetype , "Content-Length" : str ( os . path . getsize ( filename ) ) , } file_data = self . _pump . request ( "/api/user/{0}/uploads" . format ( self . _pump . client . nickname ) , method = "POST" , data = open ( filename , "rb" ) . read ( ) , headers = headers , ) data = { "verb" : "post" , "object" : file_data , } data . update ( self . serialize ( ) ) if not self . content and not self . display_name and not self . license : self . _post_activity ( data ) else : self . _post_activity ( data , unserialize = False ) if self . content : file_data [ 'content' ] = self . content if self . display_name : file_data [ 'displayName' ] = self . display_name if self . license : file_data [ 'license' ] = self . license data = { "verb" : "update" , "object" : file_data , } self . _post_activity ( data ) return self
Uploads a file from a filename on your system.

        :param filename: Path to file on your system.

        Example:
            >>> myimage.from_file('/path/to/dinner.png')