2013-05-12 53 views
-1

我使用web.py作爲我的項目的RESTful服務器,現在我遇到了一個問題,就是如何上傳文件。 在Phonegap官方文檔中,我找到了這個例子,但它是由PHP編寫的,在服務器端它使用了一個名爲的函數move_uploaded_file()。我認爲這是獲取文件然後將其保存在用戶的地方想。如何使用Web.py + phonegap上傳文件

所以,這是我的問題,有沒有類似的東西在我web.py.Or怎麼可能得到的文件與web.py?

我需要一些幫助,謝謝。

我已經完成了。 在客戶端:

function uploadPhoto(imageURI) { 
     var options = new FileUploadOptions(); 
     options.fileKey="file";#keep this name the same as server 
     ... 
     ft.upload(imageURI, "http://some.server.com/upload", win, fail, options); 
    } 

在服務器端:

def POST(self): 
    files = web.input(file={})#where the client side defined 
    data = files['file'].file.read()#got the data 
    ...do something you wanted... 

回答

0

this recipe

import web 

urls = ('/upload', 'Upload') 

class Upload: 
    def GET(self): 
     return """<html><head></head><body> 
<form method="POST" enctype="multipart/form-data" action=""> 
<input type="file" name="myfile" /> 
<br/> 
<input type="submit" /> 
</form> 
</body></html>""" 

    def POST(self): 
     x = web.input(myfile={}) 
     web.debug(x['myfile'].filename) # This is the filename 
     web.debug(x['myfile'].value) # This is the file contents 
     web.debug(x['myfile'].file.read()) # Or use a file(-like) object 
     raise web.seeother('/upload') 


if __name__ == "__main__": 
    app = web.application(urls, globals()) 
    app.run() 
+0

我看到這一點,但在客戶端,沒有形式,只是可以使用phonegap API名稱是filetranser,它將文件發送到服務器。我已經嘗試在服務器端的上述代碼獲取文件競爭或文件對象,但它不工作....... – 2013-05-12 04:54:48