zoukankan      html  css  js  c++  java
  • phoneGap API调用摄像头并上传图片


    function uploadshow(typeid) {

                // Retrieve image file location from specified source
                navigator.camera.getPicture(uploadPhoto,
                                            function(message) { alert('没有获取到照片'); },
                                            { quality: 50,
                                            destinationType: navigator.camera.DestinationType.FILE_URI,
                                           // sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY
               sourceType: // 1表示摄像头 2表示从相册获取
               (typeid==1)?navigator.camera.PictureSourceType.CAMERA:navigator.camera.PictureSourceType.PHOTOLIBRARY  }
                                            );

            }

            function uploadPhoto(imageURI) {
       $("#uploadshowtext").text("正在上传......");
                var options = new FileUploadOptions();
                options.fileKey="file";
       //alert(imageURI.fullPath);
                options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1);//安卓的地址是 context://scard/dicm/121/234  这里无文件扩展名
         //options.fileName=imageURI;
                //options.mimeType="image/jpeg";
       options.mimeType="multipart/form-data";//这两个参数修改了,后台就跟普通表单页面post上传一样 enctype="multipart/form-data"

       //options.mimeType="application/octet-stream";
       options.chunkedMode = false;

                var params = new Object();
                params.pid = kget("pid");
                params.feeid = feeid;
                options.params = params;

                var ft = new FileTransfer();
                ft.upload(imageURI, "http://server.com/uploadshow.asp?action=upload", win, fail, options);
            }

            function win(r) {
       //alert(JSON.parse(r.response).err);
       
                //alert("Code = " + r.responseCode);
                alert("上传成功");
       
               // alert("Sent = " + r.bytesSent);
            }

            function fail(error) {
                alert("An error has occurred: Code = " + error.code);           
            }

  • 相关阅读:
    ansible become与sudo
    GTID 复制、主从不一致跳过操作、快速切换master
    percona toolkit 更新至一致性检查
    oracle ldap (ODEE ODCC)复制概要
    zabbix api 批量添加主机(python3 requests)
    grafana 5.0+ templating变化
    redis sentinel 客户端
    centos7 变更默认mariadb 记录
    python3 float 计算
    企业微信开发记录
  • 原文地址:https://www.cnblogs.com/henshui/p/2512296.html
Copyright © 2011-2022 走看看