ImageServer的上传功能的说明:

每个要上传的模块需要事先在ImageServer的配置文件(Configs\Upload.config)中添加配置节点UploadAppConfig,其中节点上的Name是要传递给UploadHandler.ashx的,用于检索对应的配置信息

<?xml version="1.0" encoding="utf-8" ?>

<UploadConfig>

  <UploadAppConfigs>

    <!--商品图片上传,其中RootPath定死为neg不能做修改,程序中有些地方需要用它来计算-->

    <UploadAppConfig Name="product" RootPath="neg">

      <!--水印地址,相对于网站根目录-->

      <WatermarkPic>watermark.png</WatermarkPic>

      <!--文件大小限制(单位KB)-->

      <MaxLength>200000</MaxLength>

      <!--允许的文件类型(多个子项以逗号分隔)-->

      <AllowTypes>.jpeg,.jpg,.gif</AllowTypes>

      <!--图片缩放规格的宽度(多个子项以逗号分隔)[说明:高度是根据Resolution参数动态计算出来的。]-->

      <ImageSizes>60,68,120,160,200,240,360,450,800</ImageSizes>

      <!--图片缩放规格比例(宽度:高度,比如1:1,4:3,16:9)-->

      <Resolution>1:1</Resolution>

    </UploadAppConfig>

 

    <!--市场组图片上传,包括Banner,团购封面图等-->

    <UploadAppConfig Name="mkt" RootPath="mkt">

      <WatermarkPic></WatermarkPic>

      <MaxLength>200000</MaxLength>

      <AllowTypes>.jpeg,.jpg,.gif</AllowTypes>

      <ImageSizes></ImageSizes>

      <Resolution></Resolution>

    </UploadAppConfig>

 

    <!--富文本编辑器图片上传-->

    <UploadAppConfig Name="ueditor" RootPath="ueditor_upload_files">

      <WatermarkPic></WatermarkPic>

      <MaxLength>200000</MaxLength>

      <AllowTypes>.jpeg,.jpg,.gif,.png,.bmp</AllowTypes>

      <ImageSizes></ImageSizes>

      <Resolution></Resolution>

    </UploadAppConfig>

  </UploadAppConfigs>

</UploadConfig>

 

传服务地址:http://image.xxx.com/ UploadHandler.ashx?appName=product

其的appName根据配置节点的设置来传递。

 

传服务返回结果:

状态

说明

示例

TYPE

文件类型限制

{"message":"上传失败:不可上传文件格式为.png的文件。可上传的文件格式的为.jpeg,.jpg,.gif","original":null,"state":"TYPE","title":null,"url":null}

SIZE

文件大小限制

{"message":"上传失败:您选择的文件大小为500KB,超过允许的最大值300KB","original":null,"state":"SIZE","title":null,"url":null}

ERROR

错误

{"message":"上传失败:没有检测到可上传的文件。","original":null,"state":"SIZE","title":null,"url":null}

SUCCESS

传成功

{"message":"上传成功!","original":"332acf73-c516-4445-8e32-6774da889ca9.jpg","state":"SUCCESS","title":"dcc7c500-db92-4473-917e-232bdd4895bc.jpg","url":"mkt\/2014\/1121\/dcc7c500-db92-4473-917e-232bdd4895bc.jpg"}

 

其中url为相对ImageServer网站的地址,比如mkt/2014/1121/ dcc7c500-db92-4473-917e-232bdd4895bc.jpg,如果appNameproduct则直接返回文件名,比如dcc7c500-db92-4473-917e-232bdd4895bc.jpg

之后可以根据商品图片规格回显给用户,比如要回显P320的图片,则拼接出来的地址是http://image.xxx.com/neg/P320/dcc7c500-db92-4473-917e-232bdd4895bc.jpg

 

3.SellerPortal中上传示例:

$("#coverFileUploader").uploadify({

                "swf": "/Content/third/uploadify/uploadify.swf",

                "buttonText": "浏览...",

                //query string的方式传递appName

                "uploader": "http://image.xxx.com/UploadHandler.ashx?appName=mkt",

                "auto": false,

                //form的方式传递appName

                //"post_params":{"appName":"mkt"},

                "onSelect": function (file) {

                    $("#btnUpload").show();

                },

                "onUploadSuccess": function (file, data, response) {

                    var data = JSON.parse(data);

                    var url = "";

                    if(data.state==="SUCCESS"){

                        url = "http://image.xxx.com"+data.url;

                    }

                    $.alert(data.message);

                    $("#btnUpload").hide();

                    $("#txtGroupBuyingSmallPicUrl").val(url);

                    $("#imgSmallPic").attr("src",url);

                },

                "onUploadError": function (file, errorCode, errorMsg, errorString) {

                    $("#btnUpload").hide();

                    $.alert("传失败请重试。");

                    $("#txtGroupBuyingSmallPicUrl").val("");

                }

            });

            $("#btnUpload").click(function () {

                $("#coverFileUploader").uploadify("upload");

            });