maxcutler / python-wordpress-xmlrpc

Python library for WordPress XML-RPC integration
http://python-wordpress-xmlrpc.rtfd.org
MIT License
380 stars 129 forks source link

upload media change the file name itself #139

Open viponedream opened 4 years ago

viponedream commented 4 years ago

filepath = 'D:\APP_MY\TOOLS_MY\crawler\vars\download\wp-content/uploads/2020/07\graffiti1-c1063fa88b70424e95fe0bec6a222674-kaips.com.jpg'

` def upload(self, filepath): filename = os.path.split(filepath)[-1]

prepare metadata

    data = {
        'name': filename,
        'type': mimetypes.guess_type(filepath)[0],  # mimetype            
    }
    # read the binary file and let the XMLRPC library encode it into base64
    with open(filepath, 'rb') as img:
            data['bits'] = xmlrpc_client.Binary(img.read())
    response = self.client.call(media.UploadFile(data))
    # print (response)
    return response`

it upload well, but the file name has changed. the source file name is : graffiti1-c1063fa88b70424e95fe0bec6a222674-kaips.com.jpg it changed to be: 'graffiti1-c1063fa88b70424e95fe0bec6a222674-kaips.com.jpg' it added at last , why? How can i use my own filename?