Beispiel #1
0
        /// <summary>
        /// 删除文件
        /// </summary>
        /// <param name="bucketName">存储空间名称</param>
        /// <param name="filePath">文件地址(含http://)</param>
        /// <param name="customDmain">自定义域名</param>
        /// <param name="result">错误信息</param>
        /// <returns>是否删除成功</returns>
        public bool DeleteObject(string bucketName, string filePath, string customDomain, out string result)
        {
            string pointDmain = "http://" + bucketName + "." + EndPoint + "/"; //默认网址

            if (!string.IsNullOrEmpty(customDomain))
            {
                pointDmain = customDomain.TrimEnd('/') + "/"; //自定义网址
            }
            if (!filePath.StartsWith(pointDmain))
            {
                result = "该文件不属于OSS存储对象";
                return(false);
            }
            string fileKey = filePath.Replace(pointDmain, ""); //去除网址

            try
            {
                client.DeleteObject(bucketName, fileKey);
                result = "文件删除成功";
                return(true);
            }
            catch (Exception ex)
            {
                result = ex.Message;
                return(false);
            }
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="objectName"></param>
 public void DeleteObject(string objectName)
 {
     if (objectName != null)
     {
         objectName = objectName.Trim('/');
     }
     if (String.IsNullOrEmpty(objectName))
     {
         throw new ArgumentNullException("objectName");
     }
     try
     {
         if (client.DoesObjectExist(this.bucketName, objectName))
         {
             client.DeleteObject(this.bucketName, objectName);
         }
     }
     catch (Exception ex)
     {
         throw new StorageIOException("Delete object fail!", ex);
     }
 }