Beispiel #1
0
        public async Task <IHttpActionResult> PutRecordingDetails([FromBody] JObject value)
        {
            // Execute the query even if the title is null, we need to send the ExerciseId back.
            var userId     = this.GetUserId();
            var recorderId = (string)value["recorderId"];
            var recordName = (string)value["recordName"];
            var blobName   = UploadUtils.ConstractArtifactBlobName(userId, recorderId, recordName);

            var title  = ExerciseUtils.NormalizeExerciseTitle((string)value["title"]);
            var cardId = (Guid?)value["cardId"];
            var length = UploadUtils.DurationToLength((double)value["duration"]); // We use duration because there is a chance that the same instance of a recorder may be reused.

            var sql        = @"
update dbo.exeExercises
set Title = @Title, CardId = @CardId
output deleted.Id
where UserId = @UserId 
    and [Length] = @Length 
    and Artifact = @Artifact;
";
            var exerciseId = (await DapperHelper.QueryResilientlyAsync <int>(sql,
                                                                             new
            {
                Title = title,
                CardId = cardId,
                UserId = userId,
                Length = length,
                Artifact = blobName,
            }))
                             .SingleOrDefault();

            return(Ok(exerciseId));
        }
Beispiel #2
0
        /// <summary>
        /// 上传文档缩略图
        /// </summary>
        public void UploadArchiveThumb_POST()
        {
            String dir  = UploadUtils.GetUploadDirPath(base.CurrentSite.SiteId, "thumb_ar", true);
            string name = UploadUtils.GetUploadFileName(base.Request, "");

            UploadResultResponse(dir, name, true);
        }
        public async Task <string> SaveAudiorRecording(string recorderId, string recordName, double duration)
        {
            bool success = false;

            try
            {
                var userId = this.GetUserId();
                // recorderId comes from Audior, 13 digits, milliseconds, current Date in the browser. It is part of Artifact and will be used to update Title with the real title after upload is done.
                var blobName = UploadUtils.ConstractArtifactBlobName(userId, recorderId, recordName);

                using (var stream = Request.InputStream)
                {
                    await AzureStorageUtils.UploadBlobAsync(stream, AzureStorageUtils.ContainerNames.Artifacts, blobName, MediaType.Mp3);
                }

                var length = UploadUtils.DurationToLength(duration);
                await ExerciseUtils.CreateExercise(blobName, userId, ServiceType.IeltsSpeaking, ArtifactType.Mp3, length, null);

                success = true;
            }
            catch (Exception ex)
            {
                return("save=failed\n" + ex.Message);
            }
            // Audior expects only "save=..." in response.
            return("save=" + (success ? "ok" : "failed"));
        }
Beispiel #4
0
        /// <summary>
        /// 上传文件
        /// </summary>
        public void UploadPropertyFile_POST()
        {
            DateTime dt   = DateTime.Now;
            String   dir  = UploadUtils.GetUploadDirPath(base.CurrentSite.SiteId, "prop", true);
            string   name = UploadUtils.GetUploadFileName(base.Request, "");

            UploadResultResponse(dir, name, true);
        }
Beispiel #5
0
        /// <summary>
        /// 上传文档缩略图
        /// </summary>
        public void UploadArchiveThumb_POST()
        {
            var file = Request.File("upload_thumbnail");
            var dir  = UploadUtils.GetUploadDirPath(CurrentSite.SiteId, "image/art", true);
            var name = UploadUtils.GetUploadFileName(file, "");

            UploadResultResponse(file, dir, name, true);
        }
Beispiel #6
0
        /// <summary>
        /// 上传文档缩略图
        /// </summary>
        public void UploadArchiveThumb_POST()
        {
            var file = Request.FileIndex(0);
            var dir  = UploadUtils.GetUploadDirPath(CurrentSite.SiteId, "thumb_ar", true);
            var name = UploadUtils.GetUploadFileName(file, "");

            UploadResultResponse(dir, name, true);
        }
Beispiel #7
0
        /// <summary>
        /// 上传图片
        /// </summary>
        public void UploadImage_POST()
        {
            string uploadfor = base.Request["for"];
            //string id = base.Request["upload.id"];
            String dir  = UploadUtils.GetUploadDirPath(base.CurrentSite.SiteId, "image", true);
            string name = UploadUtils.GetUploadFileName(base.Request, uploadfor);

            UploadResultResponse(dir, name, false);
        }
Beispiel #8
0
        /// <summary>
        /// 上传分类缩略图
        /// </summary>
        public void UploadCatThumb_POST()
        {
            string uploadfor = base.Request["for"];
            //string id = base.Request["upload.id"];
            String dir  = UploadUtils.GetUploadDirPath(base.CurrentSite.SiteId, "thumb_cat", false);
            string name = UploadUtils.GetUploadFileRawName(base.Request);

            UploadResultResponse(dir, name, true);
        }
Beispiel #9
0
        /// <summary>
        /// 上传分类缩略图
        /// </summary>
        public void UploadCatThumb_POST()
        {
            var file = Request.FileIndex(0);
            //string id = base.Request.Query("upload.id");
            var dir  = UploadUtils.GetUploadDirPath(CurrentSite.SiteId, "image/cat", false);
            var name = UploadUtils.GetUploadFileRawName(file);

            UploadResultResponse(file, dir, name, true);
        }
Beispiel #10
0
        /// <summary>
        /// 上传文件
        /// </summary>
        public void UploadPropertyFile_POST()
        {
            var file = Request.FileIndex(0);
            var dt   = DateTime.Now;
            var dir  = UploadUtils.GetUploadDirPath(CurrentSite.SiteId, "prop", true);
            var name = UploadUtils.GetUploadFileName(file, "");

            UploadResultResponse(file, dir, name, true);
        }
Beispiel #11
0
        /// <summary>
        /// 上传文件
        /// </summary>
        public void UploadFile_POST()
        {
            // string uploadfor = Request.Query("for");
            // string id = Request.Query("upload.id");
            var file = Request.FileIndex(0);
            var dir  = UploadUtils.GetUploadDirPath(CurrentSite.SiteId, "file", true);
            var name = UploadUtils.GetUploadFileName(file, "");

            UploadResultResponse(file, dir, name, false);
        }
Beispiel #12
0
        /// <summary>
        /// 上传文件
        /// </summary>
        public void UploadFile_POST()
        {
            string   uploadfor = base.Request["for"];
            string   id        = base.Request["upload.id"];
            DateTime dt        = DateTime.Now;
            String   dir       = UploadUtils.GetUploadDirPath(base.CurrentSite.SiteId, "file", true);
            string   name      = UploadUtils.GetUploadFileName(base.Request, "");

            UploadResultResponse(dir, name, false);
        }
Beispiel #13
0
        public IActionResult UploadBase64([FromBody] UploadBase64Model model)
        {
            var imageUtils = UploadUtils.Instance(_hostingEnvironment);

            var relativePath = imageUtils.Save(model.Value);

            return(Ok(new
            {
                relativePath
            }));
        }
        //When 'save canvas' is clicked ...
        public IActionResult UploadWithBase64([FromBody] PostStringModel model)
        {
            //Go to UploadUtils Instance() in UploadUtils.cs
            var imageUtils = UploadUtils.Instance(_hostingEnvironment); //Create hosting env with the rootpath,etc.
            //Go to Save() method in UploadUtils.cs
            var relativePath = imageUtils.Save(model.Value);            //Relative path (wwwroot) of the image is returned

            return(Ok(new
            {
                relativePath
            }));
        }
Beispiel #15
0
        public IActionResult UploadFile(List <IFormFile> files)
        {
            if (files.Count == 0)
            {
                throw new DemoException("No file selected");
            }

            var imageUtils = UploadUtils.Instance(_hostingEnvironment);

            var relativePaths = imageUtils.Save(files);

            return(Ok(new
            {
                relativePaths
            }));
        }
Beispiel #16
0
        /// <summary>
        /// 处理上传
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public Task UploadRequest(ICompatibleHttpContext context)
        {
            context.Response.ContentType("application/json; charset=utf-8");
            var path = context.Request.GetPath();
            //String aspxUrl = path.Substring(0, path.LastIndexOf("/") + 1);
            String saveUrl = $"{(this._appPath == "/" ? "" : this._appPath)}/{this._rootPath}";

            //定义允许上传的文件扩展名
            Hashtable extTable = new Hashtable();

            extTable.Add("image", "gif,jpg,jpeg,png,bmp,webp");
            extTable.Add("flash", "swf,flv");
            extTable.Add("media", "swf,flv,mp3,wav,wma,wmv,mid,avi,mpg,asf,rm,rmvb");
            extTable.Add("file", "doc,docx,xls,xlsx,ppt,htm,html,txt,zip,rar,gz,bz2,7z");

            //最大文件大小
            int maxSize = 10240000;

            ICompatiblePostedFile imgFile = context.Request.File("imgFile");

            if (imgFile == null)
            {
                return(this.showError(context, "请选择文件。"));
            }

            String dirPath = EnvUtil.GetBaseDirectory() + this._rootPath;

            if (!Directory.Exists(dirPath))
            {
                Directory.CreateDirectory(dirPath).Create();
                //return showError(context,"上传目录不存在。");
            }

            String dirName = context.Request.Query("dir");

            if (String.IsNullOrEmpty(dirName))
            {
                dirName = "image";
            }

            if (!extTable.ContainsKey(dirName))
            {
                return(this.showError(context, "目录名不正确。"));
            }

            String fileName = imgFile.GetFileName();
            String fileExt  = Path.GetExtension(fileName).ToLower();

            if (imgFile.GetLength() > maxSize)
            {
                return(this.showError(context, "上传文件大小超过限制。"));
            }

            if (String.IsNullOrEmpty(fileExt) ||
                Array.IndexOf(((String)extTable[dirName]).Split(','), fileExt.Substring(1).ToLower()) == -1)
            {
                return(this.showError(context, "上传文件扩展名是不允许的扩展名。\n只允许" + ((String)extTable[dirName]) + "格式。"));
            }

            //创建文件夹
            dirPath += dirName + "/";
            saveUrl += dirName + "/";
            if (!Directory.Exists(dirPath))
            {
                Directory.CreateDirectory(dirPath).Create();
            }

            String ymd = DateTime.Now.ToString("yyyyMM", DateTimeFormatInfo.InvariantInfo);

            dirPath += ymd + "/";
            saveUrl += ymd + "/";
            if (!Directory.Exists(dirPath))
            {
                Directory.CreateDirectory(dirPath);
            }

            String originName  = UploadUtils.GetUploadFileName(imgFile);
            String newFileName = originName + fileExt;
            //String newFileName = DateTime.Now.ToString("yyyyMMddHHmmss_ffff", DateTimeFormatInfo.InvariantInfo) + fileExt;

            // 自动将重复的名称命名
            String targetPath = dirPath + newFileName;
            int    i          = 0;

            while (File.Exists(targetPath))
            {
                i++;
                newFileName = $"{originName}_{i.ToString()}{fileExt}";
                targetPath  = dirPath + newFileName;
            }

            SaveFile(imgFile, targetPath);

            String fileUrl = saveUrl + newFileName;

            Hashtable hash = new Hashtable();

            hash["error"] = 0;
            hash["url"]   = fileUrl;
            return(context.Response.WriteAsync(JsonAnalyzer.ToJson(hash)));
        }
Beispiel #17
0
        public void ProcessRequest(HttpContext context)
        {
            String aspxUrl = context.Request.Path.Substring(0, context.Request.Path.LastIndexOf("/") + 1);

            string siteId = Logic.CurrentSite.SiteId.ToString();
            //文件保存目录路径
            String savePath = String.Format("/{0}{1}/", CmsVariables.RESOURCE_PATH, siteId);

            //文件保存目录URL
            string appPath = Cms.Context.ApplicationPath;
            String saveUrl = String.Format("{0}/{1}{2}/", appPath == "/"?"":appPath, CmsVariables.RESOURCE_PATH, siteId);

            //定义允许上传的文件扩展名
            Hashtable extTable = new Hashtable();

            extTable.Add("image", "gif,jpg,jpeg,png,bmp");
            extTable.Add("flash", "swf,flv");
            extTable.Add("media", "swf,flv,mp3,wav,wma,wmv,mid,avi,mpg,asf,rm,rmvb");
            extTable.Add("file", "doc,docx,xls,xlsx,ppt,htm,html,txt,zip,rar,gz,bz2,7z");

            //最大文件大小
            int maxSize = 10240000;

            this.context = context;

            HttpPostedFile imgFile = context.Request.Files["imgFile"];

            if (imgFile == null)
            {
                showError("请选择文件。");
            }

            String dirPath = AppDomain.CurrentDomain.BaseDirectory + savePath;

checkDir:
            bool isCreate = false;

            if (!Directory.Exists(dirPath))
            {
                Directory.CreateDirectory(dirPath).Create();
                if (!isCreate)
                {
                    isCreate = true;
                    goto checkDir;
                }

                showError("上传目录不存在。");
            }

            String dirName = context.Request.QueryString["dir"];

            if (String.IsNullOrEmpty(dirName))
            {
                dirName = "image";
            }
            if (!extTable.ContainsKey(dirName))
            {
                showError("目录名不正确。");
            }

            String fileName = imgFile.FileName;
            String fileExt  = Path.GetExtension(fileName).ToLower();

            if (imgFile.InputStream == null || imgFile.InputStream.Length > maxSize)
            {
                showError("上传文件大小超过限制。");
            }

            if (String.IsNullOrEmpty(fileExt) || Array.IndexOf(((String)extTable[dirName]).Split(','), fileExt.Substring(1).ToLower()) == -1)
            {
                showError("上传文件扩展名是不允许的扩展名。\n只允许" + ((String)extTable[dirName]) + "格式。");
            }

            //创建文件夹
            dirPath += dirName + "/";
            saveUrl += dirName + "/";
            if (!Directory.Exists(dirPath))
            {
                Directory.CreateDirectory(dirPath).Create();
            }
            String ymd = DateTime.Now.ToString("yyyyMM", DateTimeFormatInfo.InvariantInfo);

            dirPath += ymd + "/";
            saveUrl += ymd + "/";
            if (!Directory.Exists(dirPath))
            {
                Directory.CreateDirectory(dirPath);
            }
            String originName  = UploadUtils.GetUploadFileName(context.Request);
            String newFileName = originName + fileExt;
            //String newFileName = DateTime.Now.ToString("yyyyMMddHHmmss_ffff", DateTimeFormatInfo.InvariantInfo) + fileExt;

            // 自动将重复的名称命名
            String targetPath = dirPath + newFileName;
            int    i          = 0;

            while (File.Exists(targetPath))
            {
                i++;
                newFileName = String.Format("{0}_{1}{2}", originName, i.ToString(), fileExt);
                targetPath  = dirPath + newFileName;
            }
            imgFile.SaveAs(targetPath);

            String fileUrl = saveUrl + newFileName;

            Hashtable hash = new Hashtable();

            hash["error"] = 0;
            hash["url"]   = fileUrl;
            context.Response.AddHeader("Content-Type", "text/html; charset=UTF-8");


            context.Response.Write(JsonAnalyzer.ToJson(hash));
            context.Response.End();
        }