这是我的phonegapfile文件:这个文件正在向django服务器发送数据,但是我无法将文件存储在server.py中,这将是用于捕获和存储文件的python视图函数吗?如何使用phonegap在django服务器上传文件?
<!DOCTYPE HTML>
<html>
<head>
<title>File Transfer Example</title>
<script type="text/javascript" charset="utf-8" src="cordova-2.5.0.js"></script>
<script type="text/javascript" charset="utf-8">
// Wait for Cordova to load
//
document.addEventListener("deviceready", onDeviceReady, false);
// Cordova is ready
//
function onDeviceReady() {
// Retrieve image file location from specified source
navigator.camera.getPicture(uploadPhoto,
function(message) {
alert('get picture failed');},
{ quality: 50,
destinationType: navigator.camera.DestinationType.FILE_URI,
sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY }
);
}
function uploadPhoto(imageURI) {
var options = new FileUploadOptions();
options.fileKey="file";
options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1);
options.mimeType="image/jpeg";
var params = {};
params.value1 = "test";
params.value2 = "param";
options.params = params;
var ft = new FileTransfer();
ft.upload(imageURI, encodeURI("http://something.com/uploadphonegapfil/"),win,fail,options);
}
function win(r) {
console.log("Code = " + r.responseCode);
console.log("Response = " + r.response);
console.log("Sent = " + r.bytesSent);
}
function fail(error) {
alert("An error has occurred: Code = " + error.code);
console.log("upload error source " + error.source);
console.log("upload error target " + error.target);
}
</script>
</head>
<body>
<h1>Example</h1>
<p>Upload File</p>
</body>
</html>
Views.py
@csrf_exempt
def uploadPhonegapFile(request):
print "-------- hitting the url"
to_json={}
return HttpResponse(simplejson.dumps(to_json), mimetype= 'application/json')
这上传请求命中服务器和我正在打印“-----------------击中网址“ 那么我怎样才能在这里抓到文件? 或其他有没有办法将文件存储在我的服务器文件夹?
我建议潜入调试器:只需添加'import pdb; print语句和to_json语句之间的“pdb.set_trace()”。用“./manage.py runserver”启动你的django服务器,上传这个文件,你将在你的终端上有一个很好的调试器,你可以检查'dir(request)'之类的东西等。 – mawimawi 2013-04-24 08:32:59