コード例 #1
0
        static Boolean IsImageForCompress(ImageSettings settings, HttpPostedFileBase file)
        {
            if (settings == null)
            {
                return(false);
            }
            if (file.ContentType != MediaTypeNames.Image.Jpeg)
            {
                return(false);
            }
            var fileLen = file.ContentLength / 1024 / 1024;

            if (fileLen < settings.threshold)
            {
                return(false);
            }
            return(true);
        }
コード例 #2
0
        async Task <Object> SaveFilesSql(RequestFile ru, ExpandoObject prms, HttpFileCollectionBase files)
        {
            AttachmentUpdateInfo ii = new AttachmentUpdateInfo()
            {
                UserId = prms.Get <Int64>("UserId")
            };

            if (_host.IsMultiTenant)
            {
                ii.TenantId = prms.Get <Int32>("TenantId");
            }

            ImageSettings compress = ru.imageCompress;

            var resultList = new List <AttachmentUpdateIdToken>();

            for (Int32 i = 0; i < files.Count; i++)
            {
                HttpPostedFileBase file = files[i];
                ii.Name = Path.GetFileName(file.FileName);
                ii.Mime = file.ContentType;
                if (compress != null && IsImageForCompress(compress, file))
                {
                    ii.Stream = CompressImage(file.InputStream, file.ContentType, compress.quality);
                }
                else
                {
                    ii.Stream = file.InputStream;
                }
                var result = await _dbContext.ExecuteAndLoadAsync <AttachmentUpdateInfo, AttachmentUpdateOutput>(ru.CurrentSource, ru.FileProcedureUpdate, ii);

                resultList.Add(new AttachmentUpdateIdToken()
                {
                    Id    = result.Id,
                    Name  = ii.Name,
                    Mime  = ii.Mime,
                    Token = result != null ? _tokenProvider.GenerateToken(result.Token) : null
                }
                               );
            }
            return(resultList);
        }