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

  • 相关阅读:
    Android 自定义title样式
    HDU 3094 A tree game 树删边游戏
    设计模式学习笔记观察者模式
    [Unity-7] Update和FixedUpdate
    一淘搜索网页抓取系统的分析与实现(3)—scrapy+webkit & mysql+django
    POJ 1947 树DP获得冠军
    linux 下一个 jira-6.3.6 组态 皴 翻译 迁移数据库
    阐述linux IPC(五岁以下儿童):system V共享内存
    使用OpenCV玩家营造出一个视频控制(没有声音)
    Swift编程语言学习4.1——周期
  • 原文地址:https://www.cnblogs.com/tylerdonet/p/4681060.html
Copyright © 2011-2022 走看看