コード例 #1
0
ファイル: PosController.cs プロジェクト: CocacolaSh/temp
        public JsonResult UploadPhoto()
        {
            HttpPostedFileBase uploadFiles0 = Request.Files["picUpload"];

            if (uploadFiles0 != null && uploadFiles0.ContentLength > 0 && !string.IsNullOrEmpty(uploadFiles0.FileName))
            {
                UpFileEntity fileEntity0 = new UpFileEntity()
                {
                    Size = 2048
                };
                fileEntity0.Dir       = "/VendorImages/";
                fileEntity0.AllowType = ".jpg,.jpeg,.gif,.png,.bmp";

                AttachmentInfo attch0 = UploadProvider.GetInstance("Common").UploadFile(uploadFiles0, fileEntity0);
                if (string.IsNullOrEmpty(attch0.Error))
                {
                    return(JsonMessage(true, attch0.FileName));
                }
                else
                {
                    return(JsonMessage(false, attch0.Error));
                }
            }
            return(JsonMessage(false, "上传不成功..."));
        }
コード例 #2
0
 public ActionResult Index(string a)
 {
     if (ModelState.IsValid)
     {
         UpFileEntity fileEntity0 = new UpFileEntity()
         {
             Size = 2048
         };
         fileEntity0.Dir       = "weixin/";
         fileEntity0.AllowType = ".jpg,.jpeg,.gif,.png,.bmp";
         UploadProvider.GetInstance().UploadFile(Request.Files["testfile"], fileEntity0);
     }
     return(View());
 }
コード例 #3
0
        public JsonResult UploadBanner(string id)
        {
            try
            {
                HttpPostedFileBase uploadImage = Request.Files[0];
                string             imgFileName = String.Empty; //返回的图片路径
                string             imgErr      = String.Empty; //返回的上传错误信息
                if (uploadImage != null && uploadImage.ContentLength > 0)
                {
                    IUpload      upload     = UploadProvider.GetInstance();
                    UpFileEntity fileEntity = new UpFileEntity()
                    {
                        Size = 4096, AllowType = ".jpg,.jpeg,.bmp,.gif,.png"
                    };
                    fileEntity.Dir       = "/Plugin/";
                    fileEntity.AllowType = ".jpg,.jpeg,.gif,.png,.bmp";

                    AttachmentInfo attch = upload.UploadFile(uploadImage, fileEntity);

                    if (attch != null && string.IsNullOrEmpty(attch.Error))
                    {
                        imgFileName = attch.FileName;
                    }
                    else
                    {
                        imgErr = attch.Error;
                    }
                }
                else
                {
                    imgErr = "请选择上传文件";
                }
                var res    = new JsonResult();
                var person = new { err = imgErr, msg = imgFileName };
                res.Data            = person;//返回单个对象
                res.ContentType     = "application/javascript";
                res.ContentEncoding = Encoding.UTF8;
                return(res);
            }
            catch (Exception ex)
            {
                throw new Exception("上传文件测试", ex);
            }
        }