Пример #1
0
        /// <summary>
        /// 删除附件
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static MessageRecorder <bool> DeleteObject(string key)
        {
            if (string.IsNullOrEmpty(key))
            {
                return(new MessageRecorder <bool>().SetValue(true));
            }

            var service = new AliyunOssService();

            return(service.DeleteObject(key));
        }
Пример #2
0
        /// <summary>
        /// 清理过期时间
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static MessageRecorder <bool> ClearExpiration(string key)
        {
            if (string.IsNullOrEmpty(key))
            {
                return(new MessageRecorder <bool>().SetValue(true));
            }

            var service = new AliyunOssService();

            return(service.ModifyObjectMeta(key,
                                            meta => { meta.ExpirationTime = new DateTime(2050, 1, 1); }));
        }
Пример #3
0
        /// <summary>
        /// 上传附件
        /// </summary>
        /// <param name="request">HttpRequest</param>
        /// <param name="inputName">获取指定Input控件的文件</param>
        /// <returns>上传结果信息</returns>
        public static MessageRecorder <IList <string> > Upload(
            HttpRequestBase request,
            string inputName = null)
        {
            var mr = new MessageRecorder <IList <string> > {
                Value = new List <string>()
            };
            var service = new AliyunOssService();

            for (var i = 0; i < request.Files.Count; i++)
            {
                var upload = request.Files.AllKeys[i];
                //如果指定了Input名称,则寻找对应的Input执行上传操作
                if (Equals(upload, inputName))
                {
                    continue;
                }

                var file = request.Files[i];
                if (file == null)
                {
                    continue;
                }
                if (file.ContentLength <= 0)
                {
                    continue;
                }

                // Uploaded file
                // Use the following properties to get file's name, size and MIMEType
                //int fileSize = file.ContentLength;
                //string fileName = file.FileName;
                //string mimeType = file.ContentType;

                var metadata = new ObjectMetadata
                {
                    ExpirationTime     = DateTime.Now.AddDays(1),
                    ContentLength      = file.InputStream.Length,
                    ContentType        = file.ContentType,
                    ContentDisposition = file.FileName
                };
                var key = Guid.NewGuid().ToString("N");
                var mr2 = service.PutObject(key, file.InputStream, metadata);
                mr.Append(mr2);
                mr.Value.Add(key);
            }
            return(mr);
        }
Пример #4
0
        /// <summary>
        /// 删除文件
        /// </summary>
        /// <param name="keys"></param>
        /// <returns></returns>
        public static MessageRecorder <bool> Remove(IList <string> keys)
        {
            var mr = new MessageRecorder <bool>();

            if (keys.IsNullOrEmpty())
            {
                return(mr);
            }

            var service = new AliyunOssService();

            foreach (var key in keys)
            {
                mr.Append(service.DeleteObject(key));
            }
            return(mr);
        }
Пример #5
0
 /// <summary>
 /// 获得访问地址
 /// </summary>
 /// <param name="key"></param>
 /// <returns></returns>
 public static string GetUrl(string key)
 {
     return(AliyunOssService.GetUrl(key));
 }