/// <summary> /// Deletes a specific version of a file. /// </summary> /// <param name="fileName">The name of the file to delete.</param> /// <param name="fileId">The id of the file to delete.</param> /// <exception cref="AuthenticationException">Thrown when authentication fails.</exception> /// <exception cref="ApiException">Thrown when an error occurs during client operation.</exception> async Task <IApiResults <DeleteFileVersionResponse> > IStorageFiles.DeleteAsync (string fileId, string fileName) { var request = new DeleteFileVersionRequest(fileId, fileName); return(await _client.DeleteFileVersionAsync(request, _cancellationToken)); }
public override BackblazeB2ActionResult <BackblazeB2DeleteFileResult> Execute() { DeleteFileVersionRequest deleteRequest = new DeleteFileVersionRequest { FileName = _remoteFilePath, FileId = _fileId, }; string deleteRequestJson = JsonConvert.SerializeObject(deleteRequest); byte[] payload = Encoding.UTF8.GetBytes(deleteRequestJson); HttpWebRequest webRequest = GetHttpWebRequest(_authorizationSession.APIURL + APIURL); webRequest.Method = "POST"; webRequest.Headers.Add("Authorization", _authorizationSession.AuthorizationToken); webRequest.ContentLength = payload.Length; return(SendWebRequestAndDeserialize(webRequest, payload)); }
/// <summary> /// Deletes all files contained in bucket. /// </summary> /// <param name="request">The <see cref="ListFileVersionRequest"/> to send.</param> /// <param name="dop">The degree of parallelism. Use 0 to default to <see cref="Environment.ProcessorCount"/>.</param> /// <exception cref="AuthenticationException">Thrown when authentication fails.</exception> /// <exception cref="ApiException">Thrown when an error occurs during client operation.</exception> async Task <IList <DeleteFileVersionResponse> > IStorageFiles.DeleteAllAsync (ListFileVersionRequest request, int dop) { var response = new List <DeleteFileVersionResponse>(); var files = await Files.GetEnumerableAsync(request); await files.ForEachAsync(dop, async filepath => { var deleteRequest = new DeleteFileVersionRequest(filepath.FileId, filepath.FileName); var results = await _client.DeleteFileVersionAsync(deleteRequest, _cancellationToken); if (results.IsSuccessStatusCode) { _logger.LogInformation($"Successfully deleted '{filepath.FileName}' file from '{request.BucketId}' bucket id"); response.Add(results.Response); } else { _logger.LogWarning($"Failed deleting '{filepath.FileName}' file with error: {results.Error.Message}"); } }, _cancellationToken); return(response); }