public virtual Task BulkDeleteObjectsAsync(BulkDeleteObjectRequest request) { var objectPath = !request.Path.IsNullOrWhiteSpace() ? request.Path.EnsureEndsWith('/') : ""; var filesPath = request.Objects.Select(x => CalculateFilePath(request.Bucket, objectPath + x)); foreach (var file in filesPath) { if (Directory.Exists(file)) { if (Directory.GetFileSystemEntries(file).Length > 0) { throw new BusinessException(code: OssManagementErrorCodes.ContainerDeleteWithNotEmpty); // throw new ContainerDeleteWithNotEmptyException("00101", $"Can't not delete container {name}, because it is not empty!"); } Directory.Delete(file); } else if (File.Exists(file)) { File.Delete(file); } } return(Task.CompletedTask); }
public virtual async Task BulkDeleteObjectsAsync(BulkDeleteObjectRequest request) { var ossClient = await CreateClientAsync(); var path = GetBasePath(request.Path); var aliyunRequest = new DeleteObjectsRequest(request.Bucket, request.Objects.Select(x => x += path).ToList()); ossClient.DeleteObjects(aliyunRequest); }
/// <summary> /// Delete multiple objects by id list. This method will only work for objects without any connections. /// </summary> /// <param name="type">Object id</param> /// <param name="ids">List of object ids to be deleted.</param> /// <param name="options">Request specific api options. These will override the global settings for the app for this request.</param> public async static Task MultiDeleteAsync(string type, ApiOptions options, params string[] ids) { var request = new BulkDeleteObjectRequest { Type = type, ObjectIds = ids.ToList() }; ApiOptions.Apply(request, options); var response = await request.ExecuteAsync(); if (response.Status.IsSuccessful == false) { throw response.Status.ToFault(); } }
/// <summary> /// Delete multiple objects by id list. This method will only work for objects without any connections. /// </summary> /// <param name="type">Object id</param> /// <param name="ids">List of object ids to be deleted.</param> /// <param name="options">Request specific api options. These will override the global settings for the app for this request.</param> public async static Task MultiDeleteAsync(string type, ApiOptions options, params string[] ids) { var request = new BulkDeleteObjectRequest { Type = type, ObjectIds = ids.ToList() }; ApiOptions.Apply(request, options); var response = await request.ExecuteAsync(); if (response.Status.IsSuccessful == false) throw response.Status.ToFault(); }