Domanda

m*cherrypy:python*y project is on iphone app...it require to manage profile of every user i need to upload image and store its path in database.

im working on server side coding cherrypy framewok..i need to get image by http post and store its pathname in mysql database...

can u plz give me code and description how to fetch image by http post, how to prase image, and store in database....im new to cherrypy framework, first time im using this...plz help me

i tried cherrypy doc how to upload a file :: http://docs.cherrypy.org/stable/progguide/files/uploading.html but im unable to do

È stato utile?

Soluzione

To get code working for the link you provided you'll need to add the line following my comment in the code below...

def upload(self, myFile):
    MySQLconnection = MySQLdb.connect(host=cherrypy.request.app.config['Database']['host'], 
                                 passwd=cherrypy.request.app.config['Database']['passwd'],
                                 db=cherrypy.request.app.config['Database']['db'],
                                 user=cherrypy.request.app.config['Database']['user'],
                                 port=cherrypy.request.app.config['Database']['port'], 
                                 cursorclass=DictCursor)
    MySQLcursor = MySQLconnection.cursor()
    size = 0

    # add this line
    all_data = bytearray()

    while True:
        data = myFile.file.read(8192)
        all_data += data
        if not data:
            break
        size += len(data)

        saved_file=open('upload_path', 'wb') 
        saved_file.write(all_data) 
        saved_file.close()

    MySQLcursor.execute("insert into ImagePathDatabase (path) values ('" + MySQLdb.escape_string(myFile.filename) + "')")
    MySQLcursor.execute("commit;")

Let me know if you need any more help.

Andrew

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top