i'm already solved the problem.
In the server side,using these codes:
“”“JUST POST”“”
def POST(self):
        files = web.input(file_path={})
        if 'file_path' in files:
            """setting server side dir"""
            homedir = os.getcwd()
            filedir = '%s/static/upload/img' %homedir
            
            """rename filename"""
            filepath=files.file_path.replace('\\','/')
            ext=filepath.split('.', 1)[1]

            now=datetime.datetime.now()
            t ="%d%d%d%d%d%d" 
%(now.year,now.month,now.day,now.hour,now.minute,now.second)
            
            file_name = t+'.'+ext
            """read the imge file as binary format"""
            
            try:
                with open(files.file_path, 'rb') as f_in:
                    data = f_in.read()
                f_in.close()

                with open(filedir+'/'+file_name, 'wb') as f_out:
                    f_out.write(data)
                f_out.close()
            except:
                return 'faild'
            
            return '/static/upload/img/'+file_name

在 2013年5月10日星期五UTC+8下午2时37分14秒,Johnny Jiang写道:
>
> hi all,i'm a newbie to the web.py and now using it as a RESTful server,it 
> works very well.
>
> But now i  facing a problem,that i need to upload files to the server.
>
> What i'm want to do is post a URL like:'*
> http:/server/fileupload?file_path=c:/something/else*',then upload file to 
> the server and return where the file has be stored.
>
> Is this possible?How can i do it ?I found it everywhere but got no 
> solution.I need help~
>
> Thanks.
>

-- 
You received this message because you are subscribed to the Google Groups 
"web.py" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/webpy?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to