zoukankan      html  css  js  c++  java
  • html5中上传图片

    从相册中选择图片上传

    function uploadFromAlbum(type) {
        var dirtype = "";
        if ("pick_store_license" == type || "pick_id_pic" == type) {
            dirtype = "auth";
        }
        if ("pick_store_pic" == type) {
            dirtype = "store";
        }
        plus.gallery.pick(
            function (path) {
                //选择成功
                $("#heisebg").removeClass("heisebg").addClass("heisebghid");
                $("#waitingupload").removeClass("heisebghid").addClass("heisebg");
                var task = plus.uploader.createUpload(configManager.RequstUrl + "api/common/upload",
                    { method: "POST", blocksize: 102400, priority: 100 },
                    function (upload, status) {
                        // 上传完成
                        if (status == 200) {
                            var data = JSON.parse(upload.responseText);
                  //显示图片
                  ... ... $(
    "#waitingupload").removeClass("heisebg").addClass("heisebghid"); } else { console.log("Upload failed: " + status); } } ); task.addFile( path, { key: "file" }); task.addData("dir", dirtype); task.start(); }, function (e) { console.log(e); }, { filter: "image" } ); }

    函数套函数,要分清楚当前这个函数到底有那些参数。拍照上传的方法如下:

    //从摄像头中拍照
    function uploadFromCamera(type) {
        var dirtype = "";
        if ("pick_store_license" == type || "pick_id_pic" == type) {
            dirtype = "auth";
        }
        if ("pick_store_pic" == type) {
            dirtype = "store";
        }
    
        var cmr = plus.camera.getCamera(1);
        if (null != cmr) {
            //拍照
            cmr.captureImage(function (p) {
                plus.io.resolveLocalFileSystemURL(
                p,
                function (entry) {
                    //拍照成功
                    $("#heisebg").removeClass("heisebg").addClass("heisebghid");
                    $("#waitingupload").removeClass("heisebghid").addClass("heisebg");
                    //上传图片
                    var task = plus.uploader.createUpload(configManager.RequstUrl + "/api/common/upload",
                        { method: "POST", blocksize: 102400, priority: 100 },
                        function (upload, status) {
                            // 上传完成
                            if (status == 200) {
                                var data = JSON.parse(upload.responseText);
                    //显示图片
                    ... ...
    console.log(upload.responseText); } else { console.log("Upload failed: " + status); } } ); task.addFile("file://" + entry.fullPath, { key: "file" }); task.addData("dir", dirtype); task.start(); }, function (e) { plus.ui.alert(e.message, function () { }, configManager.alerttip, configManager.alertCtip); } ); }, function (e) { }, { filename: "_doc/camera/" }); } else { plus.ui.alert("没有找到摄像头", function () { }, configManager.alerttip, configManager.alertCtip); } }

    注意这一句task.addFile("file://" + entry.fullPath, { key: "file" }); 前面要加上file://防止在ios下找不到图片路径。

  • 相关阅读:
    jquery-5 jQuery筛选选择器
    百度富文本编辑器ueditor使用启示
    前端开发思路
    世界硬币:比特币类似的评分系统!
    百度面试题 号码找到符合条件
    彩色图像--色彩空间 YIQ 、YUV 、YCbCr 、YC1C2 和I1I2I3
    HDU 4915 Parenthese sequence
    Visual FoxPro 6.0~9.0解决方案和实例文档和CD写入原件下载
    DWR入门的例子(一个)
    写自己的第二级处理器(3)——Verilog HDL行为语句
  • 原文地址:https://www.cnblogs.com/tylerdonet/p/4681060.html
Copyright © 2011-2022 走看看