幽梦紫曦

获取文件访问路径

电脑版发表于:2020/3/31 16:14
1.public dynamic GetFilePath(long nameid, string oid,int dnum)
        {
            if (string.IsNullOrEmpty(oid))
            {
                return CommonService.GetErrorResult(Const.ParamErrorTip);
            }
            try
            {
                //检查redis
                string downurl = CommonService.Redis.StringHelper.StringGet<string>(Const.DownOssFileUrl + ":" + oid);
                if (!string.IsNullOrEmpty(downurl))
                {
                    return CommonService.GetSuccessResult(downurl);
                }
                OrderFile orderFile = _orderService.GetOrderFileModelBySystemNo(oid);
                OssClient client = new OssClient(endPoint, accessKeyId, accessKeySecret);
                //获取访问url
                // 设置URL过期时间为50年,图片最好设置为1天过期,源文件1小时过期,图片获取的时候循环判断是否过期,源文件下载的时候判断过期
                DateTime expiration = DateTime.Now.AddMinutes(30);
                Uri uri = client.GeneratePresignedUri(Const.DesignerBucketName, orderFile.PrintOSSPath, expiration);
                string url = uri.ToString();
                CommonService.Redis.StringHelper.StringSet<string>(Const.DownOssFileUrl + ":" + oid, url, TimeSpan.FromMinutes(30));
                //标记下载过
                if (dnum == 0)
                {
                    try
                    {
                        _orderService.UpdateFactoryDown(nameid, oid);
                    }
                    catch { }
                }
                return CommonService.GetSuccessResult(url);
            }
            catch (Exception ex)
            {
                LogHelper.WriteError("获取下载地址错误", ex);
                return CommonService.GetErrorResult("获取下载地址错误");
            }
        }


关于TNBLOG
TNBLOG,技术分享。技术交流:群号677373950
ICP备案 :渝ICP备18016597号-1
App store Android
精彩评论
{{item.replyName}}
{{item.content}}
{{item.time}}
{{subpj.replyName}}
@{{subpj.beReplyName}}{{subpj.content}}
{{subpj.time}}
猜你喜欢