【问题标题】:Phonegap filetransfer, not working. imageuritoupload not defined?Phonegap文件传输,不工作。 imageuritoupload 未定义?
【发布时间】:2014-04-28 00:28:09
【问题描述】:

我正在尝试从我的模拟器上传图片,但我在控制台中收到错误 processMessage failed: imageUriToUpload is not defined。我按照http://docs.phonegap.com/en/3.2.0/cordova_file_file.md.html#FileTransfer 的指南进行操作

所以我在这里几乎是空白的,不知道如何解决这个问题。 uploadPhoto 应该从 capturePhoto 方法中获取 imageURI。

在客户端拍照方法:

function capturePhoto() {
            navigator.camera.getPicture(
                uploadPhoto, 
                function(message) { alert("Failed to get picture"); },
                {
                    quality: 50,
                    destinationType: navigator.camera.DestinationType.FILE_URI,
                    sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY
                }
            );
        }

客户端代码:

function uploadPhoto(imageURI) {
            var title1 = document.getElementById('title').value;
            var desc1 = document.getElementById('desc').value;

            var options = new FileUploadOptions();
            options.key = "file";
            options.fileName= imageURI.substr(imageURI.lastIndexOf('/')+1);
            options.mimeType= "image/jpeg";

            var params = new Object();
            params.title = title1;
            params.desc = desc1;

            options.params = params;
            options.chunkedMode = false;

            var ft = new FileTransfer();
            ft.upload(imageURI, encodeURI("http://lols.com/php"), win, fail, options);
        }

        function win(result) {
            console.log("Code = " + r.responseCode);
            console.log("Response = " + r.response);
            console.log("Sent = " + r.bytesSent);
            alert(r.response);
            window.location.replace("http://hp1.vlab.cs.hioa.no/Hovedprosjekt/public/mobileupload")
        }

        function fail(error) {
            alert("fail");
            console.log(evt.target.error.code);
        }

服务器代码:

<?php 
print_r($_FILES["file"]);

$a = storage_path().'/mobileupload/'.'yolo.jpg';
move_uploaded_file($_FILES["file"]["tmp_name"], $a);
?>

【问题讨论】:

    标签: javascript php android cordova


    【解决方案1】:

    options.fileName= imageURI.substr(imageURI.lastIndexOf('/')+1); 中有一个错字已修复,现在已经解决了这个错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-15
      • 1970-01-01
      • 1970-01-01
      • 2015-12-01
      • 1970-01-01
      • 2017-05-10
      • 2014-07-30
      • 1970-01-01
      相关资源
      最近更新 更多