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下找不到图片路径。

  • 相关阅读:
    Go 只读/只写channel
    MongoDB 倾向于将数据都放在一个 Collection 下吗?
    Go语言string,int,int64 ,float之间类型转换方法
    [转]流程自动化机器人(RPA)概念、原理与实践
    ESXi以及WorkStation缩减thin provision模式Linux虚拟机磁盘的方法
    Linux 安装宋体字体的简单办法
    浏览器性能简单测试
    学习面试题Day04
    学习面试题Day05
    学习面试题Day06
  • 原文地址:https://www.cnblogs.com/tylerdonet/p/4681060.html
Copyright © 2011-2022 走看看