예제 #1
0
        public ActionResult Upload(HttpPostedFileBase file)
        {
            var extension = Path.GetExtension(file.FileName).ToLower();
            var fileType  = "";

            if (extension == ".jpg" || extension == ".png" || extension == ".gif" || extension == ".bmp")
            {
                fileType = "images";
            }
            else if (extension == ".mp4")
            {
                fileType = "video";
            }
            else if (extension == ".mp3")
            {
                fileType = "audio";
            }
            else
            {
                return(Json(new JsonSimpleResponse()
                {
                    State = false, ErrorMsg = "选择的文件类型有错误"
                }));
            }
            FileManageClient client = new FileManageClient(ConfigurationManager.AppSettings["uploadUrl"]);
            var response            = client.Upload(file.FileName, file.InputStream, ConfigurationManager.AppSettings["OssSubject"], $"SmartChinese/{fileType}", true);

            return(Json(response));
        }
예제 #2
0
        public FileUploadResult Upload(string base64String)
        {
            try
            {
                string           directory = $"StuAvatar/Images";
                FileManageClient client    = new FileManageClient(ConfigurationManager.AppSettings["uploadUrl"]);
                //base64String = base64String.Replace("data:image/png;base64,", string.Empty);
                base64String = base64String.Split(',')[1];

                string fileName = Guid.NewGuid().ToString("N") + ".png";
                //Base64形式的String转成byte[]
                var              imgByte  = Convert.FromBase64String(base64String);
                MemoryStream     fs       = null;
                FileUploadResult response = null;
                using (fs = new MemoryStream(imgByte))
                {
                    response = client.Upload(fileName, fs, ConfigurationManager.AppSettings["OssSubject"], directory, true);
                }
                if (response.Code == FileManageStatusCode.Success)
                {
                    response.FileUrl = $"/{directory}/{response.FileName}";
                }
                return(response);
            }
            catch (Exception ex)
            {
                throw new Exception("网络出错了,头像上传失败");
            }
        }
예제 #3
0
    public override void Process()
    {
        string uploadFileName = null;
        var    file           = Request.Files[UploadConfig.UploadFieldName];

        uploadFileName = file.FileName;


        try
        {
            string uploadUrl    = ConfigurationManager.AppSettings["uploadUrl"];
            string subject      = ConfigurationManager.AppSettings["OssSubject"];
            string topDirectory = ConfigurationManager.AppSettings["TopDirectoryOfSubject"];
            Result.OriginFileName = uploadFileName;

            FileManageClient client = new FileManageClient(uploadUrl);
            FileUploadResult result = client.Upload(
                uploadFileName,
                file.InputStream,
                subject,
                topDirectory);
            Result.Url   = result.FileUrl;
            Result.State = UploadState.Success;
        }
        catch (Exception e)
        {
            Result.State        = UploadState.FileAccessError;
            Result.ErrorMessage = e.Message;
        }
        finally
        {
            WriteResult();
        }
    }
예제 #4
0
        private FileUploadResult Upload(byte[] audio)
        {
            var              fileType  = FileTypeEnum.Audio.ToString();
            var              fileName  = Guid.NewGuid().ToString("N") + ".mp3";
            string           directory = $"Resource/{fileType}";
            Stream           stream    = new MemoryStream(audio);
            FileManageClient client    = new FileManageClient(ConfigurationManager.AppSettings["uploadUrl"]);
            var              response  = client.Upload(fileName, stream, ConfigurationManager.AppSettings["OssSubject"], $"{directory}", true);

            if (response.Code == FileManageStatusCode.Success)
            {
                response.FileUrl = $"/{directory}/{response.FileName}";
            }
            return(response);
        }
예제 #5
0
        public ActionResult Upload(HttpPostedFileBase file)
        {
            //string url = SaveFile(file);

            //return Json(new { url = url });

            var fileTypeStr = "";
            var type        = FileTypeEnum.UnKnow;

            try
            {
                type = FileHelper.CheckFile(file);
                if (type != FileTypeEnum.UnKnow)
                {
                    fileTypeStr = type.ToString();
                }
                else
                {
                    return(Json(new JsonSimpleResponse()
                    {
                        State = false, ErrorMsg = "选择的文件类型有错误"
                    }));
                }
                string           directory = $"SchoolMgr/{fileTypeStr}";
                FileManageClient client    = new FileManageClient(ConfigurationManager.AppSettings["uploadUrl"]);
                var response = client.Upload(file.FileName, file.InputStream, ConfigurationManager.AppSettings["OssSubject"], directory, true);
                if (response.Code == Abhs.Service.Client.Results.FileManageStatusCode.Success)
                {
                    response.FileUrl = $"/{directory}/{response.FileName}";
                }
                return(Json(response));
            }
            catch (Exception ex)
            {
                var msg = "服务器异常";
                if (ex is AbhsException)
                {
                    msg = ex.Message;
                }
                return(Json(new JsonSimpleResponse()
                {
                    State = false, ErrorMsg = msg
                }));
            }
        }
예제 #6
0
        [ValidateInput(false)]//不做html验证
        public JsonResult SetPage(string pagestr)
        {
            LessonUnitBll bll      = new LessonUnitBll();
            Page          pageInfo = new Page();

            #region 解析数据
            JObject obj       = JsonConvert.DeserializeObject(pagestr) as JObject;
            string  base64Str = obj["thumbnail"].ToString().Split(',')[1];
            pageInfo.id      = Convert.ToInt32(obj["id"]);
            pageInfo.pageNum = Convert.ToInt32(obj["pageNum"]);
            pageInfo.name    = obj["name"].ToString();

            string thumbnailPath     = "UnitThumbnail";          //文件路径
            string thumbnailFileName = $"unit{pageInfo.id}.png"; //文件名称

            new Thread(() =>
            {
                byte[] arr              = Convert.FromBase64String(base64Str);
                MemoryStream ms         = new MemoryStream(arr);
                FileManageClient client = new FileManageClient(ConfigurationManager.AppSettings["uploadUrl"]);
                var response            = client.UploadCoverage(thumbnailFileName, ms, ConfigurationManager.AppSettings["OssSubject"], thumbnailPath, true);
            }).Start();                                                   //开启线程上传缩略图片

            pageInfo.thumbnail = $"/{thumbnailPath}/{thumbnailFileName}"; //拼接存储路径
            pageInfo.steps     = new List <Models.CurriculumSetViewModel.Step>();

            JArray steps = JsonConvert.DeserializeObject(obj["steps"].ToString()) as JArray;
            foreach (var s in steps)
            {
                Models.CurriculumSetViewModel.Step step = new Models.CurriculumSetViewModel.Step();
                step.stepNum = Convert.ToInt32(s["stepNum"]);
                step.actions = new List <ActionBase>();

                JArray actions = JsonConvert.DeserializeObject(s["actions"].ToString()) as JArray;
                foreach (var a in actions)
                {
                    step.actions.Add(ActionTranslator.JsonToViewData(a.ToString()));
                }
                pageInfo.steps.Add(step);
            }

            #endregion 解析数据
            int coins     = 0;
            var stepsData = pageInfo.steps.Select(s => new Domain.JsonEntity.UnitStep.Step()
            {
                id      = s.id,
                StepNum = s.stepNum,
                Actions = s.actions.Select(a => ActionTranslator.ViewDataToData(a, ref coins)).ToList()
            }).ToList();
            //修改数据
            bll.Update(new DtoLessonUnit
            {
                Id         = pageInfo.id,
                Name       = pageInfo.name,
                Screenshot = pageInfo.thumbnail,
                Status     = 0,
                Index      = pageInfo.pageNum,
                Steps      = stepsData,
                Coins      = coins
            });
            return(Json(new JsonResponse <string> {
                State = true, ErrorCode = 0, ErrorMsg = "", Data = ""
            }));
        }