【问题标题】:get forbidden response when using phonegap upload filetransfer and django使用phonegap上传文件传输和django时获得禁止响应
【发布时间】:2013-11-18 13:06:05
【问题描述】:

我想使用 phonegap 的文件传输的上传方法上传图像这是我的 html 客户端代码: 文件传输示例

<script type="text/javascript" charset="utf-8" src="phonegap-1.0.0.js"></script>
<script type="text/javascript" charset="utf-8">

    // Wait for PhoneGap to load
    //
    document.addEventListener("deviceready", onDeviceReady, false);

    // PhoneGap 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 = new Object();
        params.value1 = "test";
        params.value2 = "param";

        options.params = params;

        var ft = new FileTransfer();
        ft.upload(imageURI, "http://myserverUrl/uploadview", 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);
    }

    </script>
</head>
<body>
<h1>Example</h1>
<p>Upload File</p>
</body>
</html>

在服务器端我有一个禁止的httpresponse,我知道这是由于 csrf 属性,但我不知道如何解决它,因为我的客户端不在 django 模板中

【问题讨论】:

    标签: django cordova upload django-csrf


    【解决方案1】:

    一种方法是禁用该视图的 CSRF 检查。 检查这个:

    https://stackoverflow.com/a/16458216/273119

    【讨论】:

      猜你喜欢
      • 2012-12-19
      • 2013-10-05
      • 2013-06-09
      • 1970-01-01
      • 2010-12-22
      • 2012-02-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多