Beispiel #1
0
        /// <summary>
        /// 获取图片URL
        /// </summary>
        /// <param name="imgIds"></param>
        /// <param name="fileManager"></param>
        /// <returns></returns>
        public static async Task <List <KeyValuePair <long, string> > > GetImgUrlsAsync(List <long> imgIds, IFileManager fileManager)
        {
            List <KeyValuePair <long, string> > pairs = new List <KeyValuePair <long, string> >();
            var files = await fileManager.GetFilesByIdsAsync(imgIds);

            foreach (var item in files)
            {
                pairs.Add(new KeyValuePair <long, string>(item.Id, OssOptionUtil.GetOSSUrl(item.OssKey)));
            }
            return(pairs);
        }
Beispiel #2
0
        public BaseResult <string> UploadEvaluateImage(IFormFileCollection files)
        {
            int result_number = 0;
            //var return_result = FileUtil.UploadQiniuImage(files, FileUtil.localhost_image, hostingEnv.WebRootPath, Settings.ShopImagePrefix, out result_number);
            //阿里云
            var return_result = OssOptionUtil.UploadAliYunImage(files, FileUtil.localhost_image, hostingEnv.WebRootPath, out result_number);

            if (string.IsNullOrEmpty(return_result))
            {
                return(new BaseResult <string>(result_number));
            }
            return(new BaseResult <string>(return_result));
        }
Beispiel #3
0
        /// <summary>
        /// 获取素材分类下所有的素材
        /// </summary>
        /// <returns></returns>
        public async Task <IActionResult> GetAllFile(long tagId, int page)
        {
            if (page == 0)
            {
                page = 1;
            }
            EntitySet <Interface.Models.Results.Commons.FileResult> files = await manager.GetAllFileAsync(tagId, page);

            foreach (var item in files.Entities)
            {
                item.Url = OssOptionUtil.GetOSSUrl(item.OssKey);
            }
            return(Json(files));
        }
Beispiel #4
0
        public BaseResult <DropDownList> UploadShopImage(IFormFileCollection files, string shop_id, string shopsku_id)
        {
            //首先上传图片读取到上传的图片的路径,然后根据传递过来的参数进行添加数据库,添加完成之后返回信息
            if (string.IsNullOrEmpty(shop_id) || string.IsNullOrEmpty(shopsku_id))
            {
                return(new BaseResult <DropDownList>(808, null));
            }

            //插入之前判断这个模板下面的图片未禁用的数量是否已经是4个了,如果是4个,则不允许添加
            var count = shopImageRepository.Count(c => c.shop_id.Equals(shop_id) && c.shopsku_id.Equals(shopsku_id) && c.disable == 0);

            if (count >= 4)
            {
                return(new BaseResult <DropDownList>(3004, null));
            }

            int result_number = 0;
            //var return_result = FileUtil.UploadQiniuImage(files, FileUtil.localhost_image, hostingEnv.WebRootPath, Settings.ShopImagePrefix, out result_number);
            //阿里云
            var return_result = OssOptionUtil.UploadAliYunImage(files, FileUtil.localhost_image, hostingEnv.WebRootPath, out result_number);

            if (string.IsNullOrEmpty(return_result))
            {
                return(new BaseResult <DropDownList>(result_number, null));
            }

            ShopImageEntity shopImageEntity = new ShopImageEntity
            {
                shop_id           = shop_id,
                shopsku_id        = shopsku_id,
                shopimage_address = return_result,
                shopimage_default = false
            };
            var isTrue = shopImageRepository.Add(shopImageEntity);

            if (!isTrue)
            {
                return(new BaseResult <DropDownList>(201, null));
            }
            return(new BaseResult <DropDownList>(200, new DropDownList
            {
                name = shopsku_id + "," + shopImageEntity.shopimage_id,
                value = return_result
            }));
        }
Beispiel #5
0
        /// <summary>
        /// 素材上传OSS
        /// </summary>
        /// <returns></returns>
        public async Task <IActionResult> UploadOSS(List <IFormFile> files, String tagId)
        {
            ReturnResult result = new ReturnResult();
            long         id     = long.Parse(tagId);

            foreach (var file in files)
            {
                ReturnResult check = OssOptionUtil.CheckFile(file);
                if (check.IsSuccess == false)//判断素材是否符合上传条件
                {
                    return(Json(check));
                }
                else
                {
                    //获取OSSkey
                    Dictionary <String, String> map = OssOptionUtil.GetOSSKey(file, OssOptionUtil.localhost_image, hostingEnvironment.WebRootPath, check.Message);
                    int count = await manager.GetFileCountByOssKey(map["fileKey"]);

                    if (count > 0)
                    {
                        await manager.UpdateTime(map["fileKey"]);//更新上传时间

                        result.Message = "上传成功";
                        return(Json(result));
                    }
                    else
                    {
                        FileParameter fileParameter = OssOptionUtil.OssUpload(map["filePath"], file, check.Message, id, map["fileKey"]);
                        await manager.AddFileAsync(fileParameter);

                        result.Message = "上传成功";
                        return(Json(result));
                    }
                }
            }
            result.IsSuccess = false;
            return(Json(result));
        }
Beispiel #6
0
 public IActionResult AliyunIndex()
 {
     OssOptionUtil.OssPutObject(@"C:\Users\82069\Desktop\QQ图片20180117231453.png", "png");
     return(View());
 }