示例#1
0
        /// <summary>
        /// 批量上传图片
        /// </summary>
        /// <returns></returns>
        public ApiResult uploadImage()
        {
            try {
                if (this.imageModel != null && this.imageModel.Count > 0)
                {
                    for (int i = 0; i < this.imageModel.Count; i++)
                    {
                        string base64Image = this.imageModel[i].base64;
                        base64Image = base64Image.Substring(base64Image.IndexOf(',') + 1);
                        string imageName     = this.imageModel[i].name;
                        string extenName     = imageName.Substring(imageName.IndexOf('.'));
                        byte[] bytes         = Convert.FromBase64String(base64Image);
                        int    width         = 0;
                        string size          = FileUploadHelper.GetImgSize(base64Image, out width);
                        string imageFileName = System.DateTime.Now.ToString("yyyyMMdd") + "/" + System.DateTime.Now.ToString("yyyyMMddHHmmss") + i + ".jpg";
                        string FileName      = string.Format("/resource/images/photo/{0}/", this.customerId) + imageFileName;
                        string smallName     = string.Format("/resource/images/photo/{0}/small/", this.customerId) + imageFileName;
                        string thumbName     = string.Format("/resource/images/photo/{0}/thumb/", this.customerId) + imageFileName;

                        bool Flag = FileUploadHelper.CompressionImage(base64Image, FileName, width);
                        if (Flag)
                        {
                            FileUploadHelper.UploadSmallImage(FileName, smallName, ThumbCompress.中图);
                            FileUploadHelper.UploadSmallImage(FileName, thumbName, ThumbCompress.缩略图);
                            //FileUploadHelper.CompressionImage(base64Image, smallName, (int)ThumbCompress.小图, 80);
                            //FileUploadHelper.CompressionImage(base64Image, thumbName, (int)ThumbCompress.缩略图, 80);
                            int count = GalleryBLL.Instance.Add(new GalleryModel()
                            {
                                Callery_BigPic = FileName,
                                Callery_Customer_ID
                                                     = this.customerId,
                                Callery_Name         = imageName,
                                Callery_Size         = size,
                                Callery_SmallPic     = smallName,
                                Callery_ThumbnailPic = thumbName,
                                Callery_Time         = DateTime.Now,
                                Callery_UpdateTime   = DateTime.Now,
                                Photo_FatherID       = this.groupId
                            });
                        }
                        else
                        {
                            return(new ApiResult(HQEnums.ResultOptionType.图片失败, "上传图片失败"));
                        }
                    }
                    return(new ApiResult(HQEnums.ResultOptionType.OK, "上传图片成功"));
                }
                else
                {
                    return(new ApiResult(HQEnums.ResultOptionType.缺少请求参数, "请选择图片上传"));
                }
            } catch (Exception ex) {
                LogHelper.WriteError(string.Format("uploadImage error-->Statck:{0},Message:{1}", ex.StackTrace, ex.Message));
                return(new ApiResult(HQEnums.ResultOptionType.务器错误, "服务器错误"));
            }
        }