PhoneGap的文件传输错误(code:3,HTTP_STATUS:404)于iPhone [英] PhoneGap File Transfer Error (code: 3, http_status: 404) on iPhone

查看:389
本文介绍了PhoneGap的文件传输错误(code:3,HTTP_STATUS:404)于iPhone的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个使用PhoneGap的iOS应用程序,这将允许用户将照片上传到Web服务器。这里是我的code。

 <!DOCTYPE HTML>
< HTML和GT;
< HEAD>
    <标题>捕获照片< /标题>    <脚本类型=文/ JavaScript的字符集=utf-8SRC =科尔多瓦-1.9.0.js>< / SCRIPT>
    <脚本类型=文/ JavaScript的字符集=utf-8>        //等待的PhoneGap加载
        document.addEventListener(deviceready,onDeviceReady,FALSE);        // PhoneGap的准备
        功能onDeviceReady(){
            //这里做很酷的事情...
        }        功能的getImage(){
            //从指定源中检索图像文件位置
            navigator.camera.getPicture(uploadPhoto,功能(消息){
                                        警报('获取图片失败');
                                        },{
                                        品质:50,
                                        destinationType:navigator.camera.DestinationType.FILE_URI,
                                        sourceType的:navigator.camera.PictureSourceType.PHOTOLIBRARY
                                        }
                                        );        }
        功能uploadPhoto(imageURI){
            VAR的选择=新FileUploadOptions();
            options.fileKey =recFile;
            options.fileName = imageURI.substr(imageURI.lastIndexOf('/')+ 1);
            options.mimeType =图像/ JPEG;            VAR PARAMS =新的对象();
            params.value1 =测试;
            params.value2 =参数;            options.params =参数;            VAR英尺=新的文件传输();
            ft.upload(imageURI,http://someWebSite.com/Testing/SaveImage.asmx/SaveImage,胜利,失败的选择,真正的);
        }        功能赢(R){
            的console.log(code =+ r.response code);
            的console.log(响应=+ r.response);
            的console.log(已发送=+ r.bytesSent);
        }        功能失效(错误){
            (发生错误:code =+错误code)警报;
            警报(源=+ error.source);
            警报(HTTP_STATUS =+ error.http_status);
            的console.log(上传错误源+ error.source);
            的console.log(上传错误目标+ error.target);
        }
        < / SCRIPT>
< /头>
<身体GT;
    <按钮的onclick =的getImage();>上传一张照片< /按钮>
< /身体GT;

什么毛病我的index.html文件,或与ASMX文件的问题?

每当我尝试测试了这一点,在第四代iPod Touch,我得到了以下错误消息:

  2012-07-09 16:24:03.257的Test1 [916:707]文件传输完成与响应code 404
2012-07-09 16:24:03.260的Test1 [916:707] FileTransferError {
code = 3;
HTTP_STATUS= 404;
来源=htt​​p://someWebSite.com/Testing/SaveImage.asmx/SaveImage;
目标=文件://本地主机的/ var /移动/应用/ 5DD01E68-02F7-410B-996A- 2D70BF1A61D3的/ tmp / cdv_photo_046.jpg;}
2012-07-09 16:24:07.137的Test1 [916:707]错误:插件调试控制台没有找到,或者不是CDVPlugin。检查Cordova.plist你的插件映射。


解决方案

我一直有同样的问题(在iOS7)。为我工作的解决方案是增加了saveToPhotoAlbum参数。

  navigator.camera.getPicture(成功,失败,{
    品质:80,
    destinationType:Camera.DestinationType.FILE_URI,
    sourceType的:Camera.PictureSourceType.CAMERA,
    saveToPhotoAlbum:真
});

I am trying to create an iOS app using PhoneGap that will allow a user to upload photos to a web server. Here is my code.

<!DOCTYPE html>
<html>
<head>
    <title>Capture Photo</title>

    <script type="text/javascript" charset="utf-8" src="cordova-1.9.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() {
            // Do cool things here...
        }

        function getImage() {
            // 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="recFile";
            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://someWebSite.com/Testing/SaveImage.asmx/SaveImage", win, fail, options, true);
        }

        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);
            alert("source = " + error.source);
            alert("http_status = " + error.http_status);
            console.log("upload error source " + error.source);
            console.log("upload error target " + error.target);
        }                        
        </script>
</head>
<body>
    <button onclick="getImage();">Upload a Photo</button>
</body>

Is anything wrong with my index.html file, or is the problem with the ASMX file?

Whenever I try to test this out on a 4th generation iPod Touch, I get the following error message:

2012-07-09 16:24:03.257 Test1[916:707] File Transfer Finished with response code 404
2012-07-09 16:24:03.260 Test1[916:707] FileTransferError {
code = 3;
"http_status" = 404;
source = "http://someWebSite.com/Testing/SaveImage.asmx/SaveImage";
target = "file://localhost/var/mobile/Applications/5DD01E68-02F7-410B-996A- 2D70BF1A61D3/tmp/cdv_photo_046.jpg";}
2012-07-09 16:24:07.137 Test1[916:707] ERROR: Plugin 'Debug Console' not found, or is not a CDVPlugin. Check your plugin mapping in Cordova.plist.

解决方案

I've been having the same issue (on iOS7). The solution that worked for me was to add the "saveToPhotoAlbum" parameter.

navigator.camera.getPicture(success, fail, {
    quality: 80,
    destinationType: Camera.DestinationType.FILE_URI,
    sourceType: Camera.PictureSourceType.CAMERA,
    saveToPhotoAlbum: true
});

这篇关于PhoneGap的文件传输错误(code:3,HTTP_STATUS:404)于iPhone的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆