Exemple #1
0
 public bool Delete(string path, bool recursive)
 {
     try
     {
         client.DeleteObject(BucketName, path);
         return(true);
     }
     catch (Exception ee)
     {
         logger.Error("Delete Error:" + ee);
         return(false);
     }
 }
        ///  <summary>
        /// 删除图片 货号表
        /// </summary>
        public bool DeleteAllPicByScode()
        {
            bool flag = false;
            int  n    = -1;

            try
            {
                OssClient client = new OssClient(endpoint, accessId, accessKey);

                string   Ids   = Request.QueryString["arryId"];
                string   scode = Request.QueryString["scode"];
                string   src   = "";
                string[] arryId;
                arryId = Ids.Split(',');
                foreach (var item in arryId)
                {
                    string delsql = @"update scodepic set Def4='2',Def1='1',Def2='1',Def3='1',UserId='" + userInfo.User.Id + "' where Id='" + item + "' ";
                    src = DbHelperSQL.Query(@"select * from scodepic where Id='" + item + "'").Tables[0].Rows[0]["scodePicSrc"].ToString();
                    DbHelperSQL.ExecuteSql(@"update stylepic set Def4='2',Def1='1',Def2='1',Def3='1',UserId='" + userInfo.User.Id + "' where stylePicSrc='" + src + "' ");
                    n = DbHelperSQL.ExecuteSql(delsql);
                    client.DeleteObject(bucketName, src.Replace(@"http://best-bms.pbxluxury.com/", ""));
                }
                if (n != -1)
                {
                    flag = true;
                }
            }
            catch
            {
                flag = false;
            }
            return(flag);
        }
Exemple #3
0
        private void button6_Click(object sender, EventArgs e)
        {
            var           client     = new OssClient(endpoint, accessKeyId, accessKeySecret);
            var           keys       = new List <string>();
            ObjectListing result     = null;
            string        nextMarker = string.Empty;
            string        downloadFilename;
            string        temdirname;

            show_log(" 正在监测是否有过期文件\r\n");
            do
            {
                var listObjectsRequest = new ListObjectsRequest(downok_bucketName)
                {
                    Marker  = nextMarker,
                    MaxKeys = 1000,
                    Prefix  = prefix,
                };
                result = client.ListObjects(listObjectsRequest);

                foreach (var summary in result.ObjectSummaries)
                {
                    keys.Add(summary.Key);

                    if ((summary.Size == 0) || ((DateTime.Now - summary.LastModified).Days > 3))
                    {
                        show_log(" 删除:" + summary.Key + "\r\n");
                        client.DeleteObject(bucketName, summary.Key);
                        continue;
                    }
                }
            }while (result.IsTruncated);

            show_log(" 完成监测是否有过期文件\r\n");
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="bucketName"></param>
        /// <param name="sourcekey"></param>
        public static void DeleteObject(string bucketName, string sourcekey)
        {
            try
            {
                string key        = null;
                var    listResult = client.ListObjects(bucketName);
                foreach (var summary in listResult.ObjectSummaries)
                {
                    key = summary.Key;
                    break;
                }

                client.DeleteObject(bucketName, sourcekey);

                Console.WriteLine("Delete object succeeded");
            }
            //catch (OssException ex)
            //{
            //    Console.WriteLine("Failed with error code: {0}; Error info: {1}. \nRequestID:{2}\tHostID:{3}",
            //        ex.ErrorCode, ex.Message, ex.RequestId, ex.HostId);
            //}
            catch (Exception ex)
            {
                Console.WriteLine("Failed with error info: {0}", ex.Message);
            }
        }
Exemple #5
0
        public override void DeleteFile(IVirgoFile file)
        {
            var ossSettings = _config.FileUploadOptions.Settings.Where(x => x.Key.ToLower() == "alioss").Select(x => x.Value).FirstOrDefault();
            FileHandlerOptions groupInfo = null;

            if (string.IsNullOrEmpty(file.ExtraInfo))
            {
                groupInfo = ossSettings?.FirstOrDefault();
            }
            else
            {
                groupInfo = ossSettings?.Where(x => x.GroupName.ToLower() == file.ExtraInfo.ToLower()).FirstOrDefault();
                if (groupInfo == null)
                {
                    groupInfo = ossSettings?.FirstOrDefault();
                }
            }
            if (groupInfo == null)
            {
                return;
            }
            try
            {
                OssClient client = new OssClient(groupInfo.ServerUrl, groupInfo.Key, groupInfo.Secret);
                client.DeleteObject(groupInfo.GroupLocation, file.Path);
            }
            catch { }
            return;
        }
Exemple #6
0
        /// <summary>
        /// 删除文件
        /// </summary>
        public static bool Delete(this OSSSetting setting, string objectName)
        {
            OssClient          client = new OssClient(setting.endpoint, setting.accessKeyId, setting.accessKeySecret);
            DeleteObjectResult result = client.DeleteObject(setting.bucketName, objectName);

            return(true);
        }
Exemple #7
0
        public ValueTask <bool> Delete(FileObject fileObject)
        {
            bool result = true;
            var  key    = fileObject.FileInfo.FullPath;

            if (key.IsNull())
            {
                result = false;
            }

            // 创建OssClient实例。
            var client = new OssClient(_config.Endpoint, _config.AccessKeyId, _config.AccessKeySecret);

            try
            {
                // 删除文件
                client.DeleteObject(_config.BucketName, key);

                result = true;
            }
            catch (Exception ex)
            {
                _logger.LogError("阿里云OSS文件删除异常:{@ex}", ex);
            }
            return(new ValueTask <bool>(result));
        }
Exemple #8
0
        public void DeleteFromNetwork(string name, string relativePath)
        {
            string savePath = checkPath(relativePath);

            savePath = savePath + name;
            OssClient client = new OssClient(OSS_ENDPOINT, ALIYUN_ACCESS_KEY_ID, ALIYUN_ACCESS_KEY_SECRET);

            client.DeleteObject(OSS_BUCKETNAME, savePath);
        }
        public ActionResult DeleteFile(int id, string filename)
        {
            SetServiceUrl();
            _client.AppealFileDelete(id);
            OssClient ossClient = new OssClient(endpoin, accessid, accessKey);

            ossClient.DeleteObject("vgic", filename);

            return(Json(true));
        }
Exemple #10
0
        public bool Remove(string key)
        {
            if (string.IsNullOrEmpty(key))
            {
                return(false);
            }

            return(run(() => {
                m_client.DeleteObject(m_bucket, key);
            }));
        }
Exemple #11
0
 /// <summary>
 /// 删除文件
 /// </summary>
 /// <param name="key">文件唯一标识</param>
 public void Delete(string key)
 {
     try
     {
         _ossClient.DeleteObject(_bucketName, key);
     }
     catch (Exception ex)
     {
         throw new Exception(ex.ToString());
     }
 }
Exemple #12
0
 public void Delete(string resourceKeyWithPrefix)
 {
     try
     {
         client.DeleteObject(AliResourceSection.Instance.BucketName, resourceKeyWithPrefix);
     }
     catch (Exception error)
     {
         logger.Fatal(string.Format("删除键为{0}的资源发生异常:", resourceKeyWithPrefix), error);
     }
 }
Exemple #13
0
 /// <summary>
 /// 删除oss文件
 /// </summary>
 /// <param name="DownloadPath">文件路径</param>
 /// <returns></returns>
 public bool DeleteObject(string DownloadPath)
 {
     try
     {
         client.DeleteObject(bucketName, DownloadPath);
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Exemple #14
0
        public static void CreateEmptyFolder()
        {
            const string accessKeyId     = "<your access key id>";
            const string accessKeySecret = "<your access key secret>";
            const string endpoint        = "<valid endpoint>";

            var client = new OssClient(endpoint, accessKeyId, accessKeySecret);

            const string bucketName = "<your bucket>";
            // Note: key treats as a folder and must end with slash.
            const string key      = "yourfolder/";
            var          created  = false;
            var          uploaded = false;

            try
            {
                // create bucket
                client.CreateBucket(bucketName);
                created = true;
                Console.WriteLine("Created bucket name: " + bucketName);

                // put object with zero bytes stream.
                using (MemoryStream memStream = new MemoryStream())
                {
                    PutObjectResult ret = client.PutObject(bucketName, key, memStream);
                    uploaded = true;
                    Console.WriteLine("Uploaded empty object's ETag: " + ret.ETag);
                }
            }
            catch (OssException ex)
            {
                if (ex.ErrorCode == OssErrorCode.BucketAlreadyExists)
                {
                    Console.WriteLine("Bucket '{0}' already exists, please modify and recreate it.", bucketName);
                }
                else
                {
                    Console.WriteLine("CreateBucket Failed with error info: {0}; Error info: {1}. \nRequestID:{2}\tHostID:{3}",
                                      ex.ErrorCode, ex.Message, ex.RequestId, ex.HostId);
                }
            }
            finally
            {
                if (uploaded)
                {
                    client.DeleteObject(bucketName, key);
                }
                if (created)
                {
                    client.DeleteBucket(bucketName);
                }
            }
        }
Exemple #15
0
 /// <summary>
 /// 删除文件
 /// </summary>
 private static void DeleteObject()
 {
     try
     {
         _client.DeleteObject(_bucketName, _key);
         Console.WriteLine("删除文件成功");
     }
     catch (Exception ex)
     {
         Console.WriteLine("删除文件失败.原因: {0}", ex.Message);
     }
 }
Exemple #16
0
 public void delete(System.String filename)
 {
     try
     {
         // 删除文件
         client.DeleteObject(bucketName, filename);
     }
     catch (System.Exception ex)
     {
         throw new System.Exception("fail to delete the file!");
     }
 }
Exemple #17
0
 /// <summary>
 /// 列出指定存储空间下的特定文件
 /// </summary>
 /// <param name="bucketName">存储空间的名称</param>
 /// <param name="key">文件的名称</param>
 public string DeleteObject(string bucketName, string key)
 {
     try
     {
         ossClient.DeleteObject(bucketName, key);
         return("Delete object succeeded");
     }
     catch (Exception ex)
     {
         return(string.Format("Delete object failed. {0}", ex.Message));
     }
 }
        public static void CreateEmptyFolder()
        {
            const string accessKeyId = "<your access key id>";
            const string accessKeySecret = "<your access key secret>";
            const string endpoint = "<valid endpoint>";

            var client = new OssClient(endpoint, accessKeyId, accessKeySecret);

            const string bucketName = "<your bucket>";
            // Note: key treats as a folder and must end with slash.
            const string key = "yourfolder/";
            var created = false;
            var uploaded = false;
            try
            {
                // create bucket
                client.CreateBucket(bucketName);
                created = true;
                Console.WriteLine("Created bucket name: " + bucketName);

                // put object with zero bytes stream.
                using (MemoryStream memStream = new MemoryStream())
                {
                    PutObjectResult ret = client.PutObject(bucketName, key, memStream);
                    uploaded = true;
                    Console.WriteLine("Uploaded empty object's ETag: " + ret.ETag);
                }
            }
            catch (OssException ex)
            {
                if (ex.ErrorCode == OssErrorCode.BucketAlreadyExists)
                {
                    Console.WriteLine("Bucket '{0}' already exists, please modify and recreate it.", bucketName);
                }
                else
                {
                    Console.WriteLine("CreateBucket Failed with error info: {0}; Error info: {1}. \nRequestID:{2}\tHostID:{3}",
                        ex.ErrorCode, ex.Message, ex.RequestId, ex.HostId);
                }
            }
            finally
            {
                if (uploaded)
                {
                    client.DeleteObject(bucketName, key);
                }
                if (created)
                {
                    client.DeleteBucket(bucketName);
                }
            }
        }
 public bool DeleteObject(string bucketName, string key)
 {
     try
     {
         var client = new OssClient(_config.Endpoint, _config.AccessKeyId, _config.AccessKeySecret);
         var res    = client.DeleteObject(bucketName, key);
         return(res.HttpStatusCode == HttpStatusCode.OK || res.HttpStatusCode == HttpStatusCode.NoContent);
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
 /// <summary>
 /// 删除数据
 /// </summary>
 /// <param name="fileId"></param>
 public void DeleteObject(string fileId)
 {
     try
     {
         OssClient client = new OssClient(m_endPoint, m_keyID, m_keySecret);
         // 删除文件。
         client.DeleteObject(m_bucket, fileId);
     }
     catch (Exception e)
     {
         throw e;
     }
 }
 /// <summary>
 /// Delete object
 /// </summary>
 /// <param name="key">object name</param>
 /// <remarks>if you want to delete folder,append "/" in the end</remarks>
 public bool DeleteObject(string name)
 {
     try
     {
         client.DeleteObject(bucketName, name);
         return(true);
     }
     catch (OssException ex)
     {
         lastError = ex;
         return(false);
     }
 }
        public Task <bool> DeleteFileAsync(string path, CancellationToken cancellationToken = default)
        {
            if (String.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException(nameof(path));
            }

            try {
                _client.DeleteObject(_bucket, NormalizePath(path));
                return(Task.FromResult(true));
            } catch (Exception) {
                return(Task.FromResult(false));
            }
        }
Exemple #23
0
        /// <summary>
        /// 删除文件
        /// </summary>
        public MessageRecorder <bool> DeleteObject(string key)
        {
            var r = new MessageRecorder <bool>();

            try
            {
                _client.DeleteObject(BucketName, key);
                return(r.Info("删除文件成功").SetValue(true));
            }
            catch (Exception ex)
            {
                return(r.Error($"删除文件失败. 原因:{ex.Message}"));
            }
        }
        //删除相册(相册名后面加"/")
        public void DeleteObjectss()
        {
            var client = new OssClient("oss-cn-shenzhen.aliyuncs.com", "LTAId7dsrQHujhU5", "O3nQOqai4yXrvGCKNbvgrKuU8f7U7p");

            try
            {
                client.DeleteObject("igets", "adad/");
                Console.WriteLine("Delete object succeeded");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Delete object failed, {0}", ex.Message);
            }
        }
        /// <summary>
        /// 删除单个文件
        /// </summary>
        /// <param name="fileRoute"></param>
        /// <returns></returns>
        public static bool DeleteObject(string fileRoute)
        {
            try
            {
                var client = new OssClient(Endpoint, AccessKeyId, AccessKeySecret);
                client.DeleteObject(BucketName, fileRoute);

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Exemple #26
0
        public static void AppendObjectProgress(string bucketName)
        {
            const string key      = "AppendObjectProgress";
            long         position = 0;

            try
            {
                using (var fs = File.Open(fileToUpload, FileMode.Open))
                {
                    var request = new AppendObjectRequest(bucketName, key)
                    {
                        ObjectMetadata = new ObjectMetadata(),
                        Content        = fs,
                        Position       = position
                    };
                    request.StreamTransferProgress += streamProgressCallback;

                    var result = client.AppendObject(request);
                    position = result.NextAppendPosition;

                    Console.WriteLine("Append object succeeded, next append position:{0}", position);
                }
            }
            catch (OssException ex)
            {
                Console.WriteLine("Failed with error code: {0}; Error info: {1}. \nRequestID:{2}\tHostID:{3}",
                                  ex.ErrorCode, ex.Message, ex.RequestId, ex.HostId);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Failed with error info: {0}", ex.Message);
            }
            finally
            {
                client.DeleteObject(bucketName, key);
            }
        }
Exemple #27
0
        public void Delete(string prefix)
        {
            OssClient     client = new OssClient(OssConfig.AccessId, OssConfig.AccessKey);
            ObjectListing ol     = null;

            do
            {
                ol = client.ListObjects(ossConfig.BucketName, prefix);
                foreach (var v in ol.ObjectSummaries)
                {
                    client.DeleteObject(ossConfig.BucketName, v.Key);
                    Console.WriteLine(v.Key + " 删除成功.");
                }
            } while (ol.IsTrunked);
        }
 /// <summary>
 ///     删除对象
 /// </summary>
 /// <param name="containerName"></param>
 /// <param name="blobName"></param>
 public async Task DeleteBlob(string containerName, string blobName)
 {
     await Task.Run(() =>
     {
         try
         {
             _ossClient.DeleteObject(containerName, blobName);
         }
         catch (Exception ex)
         {
             throw new StorageException(StorageErrorCode.PostError.ToStorageError(),
                                        new Exception(ex.ToString()));
         }
     });
 }
Exemple #29
0
        public bool DeleteImage(string fileName)
        {
            var ossClient = new OssClient(config.endpoint, config.accessKeyId, config.accessKeySecret);

            try
            {
                ossClient.DeleteObject(config.Bucket, fileName);
                return(true);
            }
            catch (Exception ex)
            {
                Console.WriteLine("删除文件失败, {0}", ex.Message);
                return(false);
            }
        }
Exemple #30
0
        /// <summary>
        /// Deletes the BLOB.
        /// </summary>
        /// <param name="storageIdentifier">The storage identifier.</param>
        public override void DeleteBlob(BinaryStorageIdentifier storageIdentifier)
        {
            try
            {
                storageIdentifier.CheckNullObject(nameof(storageIdentifier));
                storageIdentifier.Container.CheckEmptyString(nameof(storageIdentifier.Container));
                storageIdentifier.Identifier.CheckEmptyString(nameof(storageIdentifier.Identifier));

                client.DeleteObject(storageIdentifier.Container, storageIdentifier.Identifier);
            }
            catch (Exception ex)
            {
                throw ex.Handle(storageIdentifier);
            }
        }
Exemple #31
0
 /// <summary>
 /// 删除单个文件
 /// </summary>
 /// <param name="filePath"></param>
 public void DeleteObj(string filePath)
 {
     try
     {
         client.DeleteObject(Config.Bucket, filePath);
     }
     catch (OssException e)
     {
         Debug.Log("删除文件出错:" + e.Message);
     }
     catch (System.Exception e)
     {
         Debug.Log("删除文件出错:" + e.Message);
     }
 }
 public ActionResult Delete(int bfid)
 {
     BLLBFInfo bllbfinfo = new BLLBFInfo();
     var bfinfo = bllbfinfo.Find(bfid);
     OssClient oc = new OssClient(AccessKeyID, AccessKeySecret);
     oc.DeleteObject(BucketName, bfinfo.OSSFileName);
     bllbfinfo.Delete(bfinfo);
     return View();
 }