Пример #1
0
        public string StoreImage(string file_name, byte[] image_data, string dir_name,
                                 string content_type)
        {
            string key = string.Empty;

            try
            {
                var ossClient = new OssClient(config_oss_endpoint, config_oss_access_id, config_oss_access_key);
                var meta      = new ObjectMetadata();
                meta.ContentType = content_type;
                key = string.Format("{0}/{1}", dir_name, file_name);

                PutObjectResult result = ossClient.PutObject(config_oss_bucket, key, new MemoryStream(image_data), meta);
                //上传图片
                //Logger.Info("保存图片{0}到OSS", file_name);
            }
            catch (Exception ex)
            {
                //Logger.Exception(ex, "保存图片{0}到OSS失败,将保存到暂存区{1}", file_name, config_oss_temp_path+dir_name);

                try
                {
                    FileOperationHelper.Save(image_data, config_oss_temp_path, file_name);
                }
                catch (Exception)
                {
                    //Logger.Exception(ex, "保存图片{0}到暂存区失败", file_name);
                }
            }

            return(string.Format("http://{0}.oss-cn-hangzhou.aliyuncs.com/{1}", config_oss_bucket, key));
        }