七牛云技术文档 #

七牛云服务地址:https://portal.qiniu.com/kodo/overview

官方SDK文档:https://developer.qiniu.com/kodo/1237/csharp

Git地址:https://github.com/qiniu/csharp-sdk.git

卡侬件管理-新建存储空间

img

可绑定cdn加速域名

img

配置参数

"QiNiu": {

"AccessKey": "QSvtvN4Ons1CiNzaMGqx8XmDaiM1L0ZqSwJ2YoTn",

"SecretKey": "yagRd-cBOVhkRGGT-o_reMqNVjI8_k7YwoTXkhrm",

"CdnUrl": "http://img.blsct.com",

"ProductsCdnUrl": "https://img.blsct.com",//展示cdn前缀

},

密钥获取地址:https://portal.qiniu.com/user/key

从NuGet来安装,以Visual Studio 2013/2015为例(如果您的Visual Studio没有安装NuGet,请先[安装](http://docs.nuget.org/docs/start-here/installing-nuget" \t "https://developer.qiniu.com/kodo/1237/_blank))。打开NuGet程序包管理器搜索Qiniu或者在控制台中键入以下命令:

Install-Package Qiniu

也可以直接从源码编译

git clone https://github.com/qiniu/csharp-sdk

调用demo:

上传                   
var bytes = QiNiuCloudHelper.DownloadHttpsFile(result.getImageUrl(),false);
                            //var suffixName = $"_BaiduAI_Img_{DateTime.Now:yyyyMMddHHmmss}";
                            var suffixName = $"_AliAI_Img_{DateTime.Now:yyyyMMddHHmmss}";
                            var guid = Guid.NewGuid().ToString();
                            var ext = ImageToolHelper.GetImgFileExtension(dto.ImgPath);
                            var serverPath = guid + suffixName + "." + ext;
                            var results = await QiNiuCloudHelper.UploadStreamAsync(serverPath, bytes);
                            if (results.Code != 200) //请选择上传图片到七牛云失败!
                            {
                                dto.IsReplace = true;
                                dto.IsError = true;
                                dto.ErrorMessage = "上传图片到七牛云失败";
                            }
                            else
                            {
                                var urlPath = ServiceFabric.Extension.ConfigManagerConf.GetValue("QiNiu:CdnUrl") + "/" + serverPath;
                                var qiNiuFileInfo = QiNiuCloudHelper.GetQiNiuFileInfo(urlPath);
                                dto.NewImgPath = urlPath + "?imageView2/0/format/jpg/q/75";
                                dto.Width = qiNiuFileInfo.Width;
                                dto.IsReplace = true;
                                dto.Height = qiNiuFileInfo.Height;
                            }






		    var bytes = Convert.FromBase64String(ds);
                    var suffixName = $"_BaiduAI_Img_{DateTime.Now:yyyyMMddHHmmss}";
                    var guid = Guid.NewGuid().ToString();
                    var ext = ImageToolHelper.GetImgFileExtension(input.ImgPath);
                    var serverPath = guid + suffixName + "." + ext;
                    var results = await QiNiuCloudHelper.UploadStreamAsync(serverPath, bytes);
                    dto.IsReplace = true;
                    if (results.Code != 200) //请选择上传图片到七牛云失败!
                    {
                        dto.IsError = true;
                        dto.ErrorMessage = "上传图片到七牛云失败";
                    }
                    else
                    {
                        var urlPath = ServiceFabric.Extension.ConfigManagerConf.GetValue("QiNiu:CdnUrl") + "/" +
                                      serverPath;
                        var qiNiuFileInfo = QiNiuCloudHelper.GetQiNiuFileInfo(urlPath);
                        dto.NewImgPath = urlPath+ "?imageView2/0/format/jpg/q/75";
                        dto.Width = qiNiuFileInfo.Width;
                        dto.Height = qiNiuFileInfo.Height;
                    }


七牛云拉取线上
var specImages=new List<string>();
var uploadDic = specImages.Select(m => new KeyValuePair<string, string>(m, $"{Guid.NewGuid()}.{ImageToolHelper.GetImgFileExtension(m)}")).ToList();
var uploadRet = await QiNiuCloudHelper.FetchFilesAsync(uploadDic.ToDictionary(m => m.Key, m => m.Value));

//获取图片路径
var ImgPath = QiNiuCloudHelper.CreatePublishUrl("文件名");
//获取图片信息
var qiNiuFileInfo = QiNiuCloudHelper.GetQiNiuFileInfo(urlPath);
上次更新: 3/8/2023, 4:23:32 PM