private void DeleteLastObject() { _storageClient.DeleteObject(new DeleteObjectRequest { Resource = new Uri(_objectId, UriKind.Relative) }); }
public Material Transcribe(string fnAudio, string langCode) { // Keep storage client for full operation; will be removing file at the end StorageClient sc = null; Bucket bucket = null; try { sc = StorageClient.Create(GoogleCredential.FromFile(fnCredential)); // Get out bucket, create on demand var buckets = sc.ListBuckets(projectId); foreach (var x in buckets) { if (x.Name == bucketName) { bucket = x; } } if (bucket == null) { bucket = sc.CreateBucket(projectId, bucketName); } // Kill all existing objects var objs = sc.ListObjects(bucketName); foreach (var x in objs) { sc.DeleteObject(x); } // Upload the damned thing using (var f = File.OpenRead(fnAudio)) { sc.UploadObject(bucketName, objName, null, f); } // NOW RECOGNIZE var mat = transcribeFromObject("gs://" + bucketName + "/" + objName, langCode); return(mat); } finally { // Delete all objects in bucket if (bucket != null) { var objs = sc.ListObjects(bucketName); foreach (var x in objs) { sc.DeleteObject(x); } } // Adios storage jerk if (sc != null) { sc.Dispose(); } } }
public void DeleteObject(string fileName) { _client.DeleteObject( _bucketName, fileName ); }
/// <summary> /// Deletes all the objects from the bucket /// </summary> /// <param name="client">Storage client</param> /// <param name="keys">Keys of objects to delete</param> private void DeleteObjects(StorageClient client, List <string> keys) { foreach (var key in keys) { client.DeleteObject(_connectionInfo.BucketName, key); } }
/// <summary> /// Deletes a file to the destination repository /// </summary> public bool Delete(string file, bool wideDisplay) { file = file.Replace("\\", "/"); file = Helpers.RemoveRootSlash(file); try { _client.DeleteObject(_bucketName, file.ToLower()); string displayName = Helpers.FormatDisplayFileName(wideDisplay, file); Logger.WriteLog(ErrorCodes.GcsBucketDestination_FileDeleted, $"del dst {displayName}", Severity.Information, VerboseLevel.User); return(true); } catch (Google.GoogleApiException ex) { if (ex.HttpStatusCode == System.Net.HttpStatusCode.NotFound) { return(false); } else { throw; } } }
public void ExportCsv() { // TODO: Make this simpler in the wrapper var projectId = _fixture.ProjectId; var datasetId = _fixture.GameDatasetId; var historyTableId = _fixture.HistoryTableId; string bucket = "bigquerysnippets-" + Guid.NewGuid().ToString().ToLowerInvariant(); string objectName = "table.csv"; if (!WaitForStreamingBufferToEmpty(historyTableId)) { Console.WriteLine("Streaming buffer not empty after 30 seconds; not performing export"); return; } // Sample: ExportCsv BigqueryClient client = BigqueryClient.Create(projectId); // Create a storage bucket; in normal use it's likely that one would exist already. StorageClient storageClient = StorageClient.Create(); storageClient.CreateBucket(projectId, bucket); string destinationUri = $"gs://{bucket}/{objectName}"; Job job = client.Service.Jobs.Insert(new Job { Configuration = new JobConfiguration { Extract = new JobConfigurationExtract { DestinationFormat = "CSV", DestinationUris = new[] { destinationUri }, SourceTable = client.GetTableReference(datasetId, historyTableId) } } }, projectId).Execute(); // Wait until the export has finished. var result = client.PollJob(job.JobReference); // If there are any errors, display them *then* fail. if (result.Status.ErrorResult != null) { foreach (var error in result.Status.Errors) { Console.WriteLine(error.Message); } } Assert.Null(result.Status.ErrorResult); MemoryStream stream = new MemoryStream(); storageClient.DownloadObject(bucket, objectName, stream); Console.WriteLine(Encoding.UTF8.GetString(stream.ToArray())); // End sample storageClient.DeleteObject(bucket, objectName); storageClient.DeleteBucket(bucket); }
public void Dispose() { var objectsToDelete = _client.ListObjects(Config["GoogleBucket"], ContainerPrefix); foreach (var obj in objectsToDelete) { _client.DeleteObject(Config["GoogleBucket"], obj.Name); } }
private void DeleteExistingFiles() { var objects = _client.ListObjects(_bucket).ToList(); foreach (var obj in objects) { Console.WriteLine($"Deleting {obj.Name}"); _client.DeleteObject(obj); } }
/// <summary> /// /// <para>DeleteFile:</para> /// /// <para>Deletes a file from File Service, caller thread will be blocked before it is done</para> /// /// <para>Check <seealso cref="IBFileServiceInterface.DeleteFile"/> for detailed documentation</para> /// /// </summary> public bool DeleteFile( string _BucketName, string _KeyInBucket, Action <string> _ErrorMessageAction = null) { if (GSClient == null) { _ErrorMessageAction?.Invoke("BFileServiceGC->DeleteFile: GSClient is null."); return(false); } try { GSClient.DeleteObject(_BucketName, _KeyInBucket); } catch (Exception) { return(false); } return(true); }
public void DeleteFile(string fileNameForStorage) { try { if (storageClient.GetObject(bucketName, fileNameForStorage) != null) { storageClient.DeleteObject(bucketName, fileNameForStorage); } } catch (Exception e) { Console.WriteLine(e.Message); } }
public void DeleteFile(string fileName, string bucketName = "") { EnsureBucketExist(bucketName); try { _storageClient.DeleteObject(_bucketName, fileName); } catch (GoogleApiException gex) { _logger.LogError(-1, gex, gex.Error.Message); throw; } }
public void delete(string bucket_name, params string[] key_names) { foreach (string key_name in key_names) { try { client.DeleteObject(bucket_name, key_name); } catch (Exception ex) { throw new Exception("Error while trying to delete \"" + bucket_name + "\\" + key_name + "\" from GCP. GCP error message: " + ex.Message); } } }
public void Dispose() { int retryDelayMs = 0; for (int errorCount = 0; errorCount < 4; ++errorCount) { Thread.Sleep(retryDelayMs); retryDelayMs = (retryDelayMs + 1000) * 2; List <Google.Apis.Storage.v1.Data.Object> objectsInBucket = new List <Google.Apis.Storage.v1.Data.Object>(); try { objectsInBucket = _storage.ListObjects(BucketName).ToList(); } catch (Google.GoogleApiException e) when(e.Error.Code == 404) { // Bucket does not exist or is empty. } // Try to delete each object in the bucket. foreach (var obj in objectsInBucket) { try { _storage.DeleteObject(obj); } catch (Google.GoogleApiException) { continue; } } try { _storage.DeleteBucket(BucketName); } catch (Google.GoogleApiException e) when(e.Error.Code == 404) { return; // Bucket does not exist. Ok. } catch (Google.GoogleApiException) { continue; } } }
private static void DeleteBucket(StorageClient client, string bucket) { var objects = client.ListObjects(bucket, options: new ListObjectsOptions { Versions = true }); foreach (var obj in objects) { client.DeleteObject(bucket, obj.Name, new DeleteObjectOptions { Generation = obj.Generation }); Console.WriteLine($"Deleted {bucket} / {obj.Name} / v{obj.Generation}"); } client.DeleteBucket(bucket); Console.WriteLine($"Deleted {bucket}"); }
private void ArchiveProcessedFilesFromBucket(string filename, bool isNonMsd1File) { string filebucket = _settings.AsciiBucket; string destinationBucket = isNonMsd1File ? _settings.PortAsciiBucket : _settings.ArchivedAsciiBucket; StorageClient storageClient = StorageClient.Create(); foreach (var Item in storageClient.ListObjects(filebucket)) { if (filename.Contains(Item.Name)) { storageClient.CopyObject(filebucket, Item.Name, destinationBucket, Item.Name); storageClient.DeleteObject(filebucket, Item.Name); } } File.Delete(filename); }
private void DeleteBucket(StorageClient client, string bucket, string userProject) { // TODO: We shouldn't need the project ID here. var objects = client.ListObjects(bucket, null, new ListObjectsOptions { Versions = true, UserProject = userProject }).ToList(); foreach (var obj in objects) { client.DeleteObject(obj, new DeleteObjectOptions { Generation = obj.Generation, UserProject = userProject }); } client.DeleteBucket(bucket, new DeleteBucketOptions { UserProject = userProject }); }
/// <summary> /// Returns true if the file has been deleted /// </summary> private bool ObjectDelete(string objectName) { try { _client.DeleteObject(_bucketName, objectName.ToLower()); return(true); } catch (Google.GoogleApiException ex) { if (ex.HttpStatusCode == System.Net.HttpStatusCode.NotFound) { return(false); } else { throw; } } }
public void Dispose() { RetryRobot robot = new RetryRobot() { MaxTryCount = 10, ShouldRetry = (e) => true, }; foreach (KeyValuePair <string, SortedSet <string> > bucket in _garbage) { foreach (string objectName in bucket.Value) { robot.Eventually(() => { _storage.DeleteObject(bucket.Key, objectName); }); } } _garbage.Clear(); }
public void Dispose() { var robot = new RetryRobot() { MaxTryCount = 10, ShouldRetry = (e) => true, }; foreach (var bucket in _garbage) { foreach (var objectName in bucket.Value) { robot.Eventually(() => { _storage.DeleteObject(bucket.Key, objectName); }); } } _garbage.Clear(); }
private void TestBucket(string projectId, StorageClient storageClient) { var bucketName = this.GetDefaultBucketName(projectId); var fileName = "FirebaseStorageTest.txt"; var content = "FirebaseStorageTest"; using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(content))) { var obj1 = storageClient.UploadObject(bucketName, fileName, "text/plain", stream); Assert.Equal(bucketName, obj1.Bucket); } using (var stream = new MemoryStream()) { storageClient.DownloadObject(bucketName, fileName, stream); Assert.Equal(content, Encoding.UTF8.GetString(stream.ToArray())); } storageClient.DeleteObject(bucketName, fileName); }
static void DeleteObject(string bucketName, string objectName) { storageClient.DeleteObject(bucketName, objectName); Console.WriteLine($"{objectName} silindi."); }
public Task Remove(ILightAttachment attachment) { _client.DeleteObject(this.Container, attachment.ResourceId + "/" + attachment.Id); return(Task.CompletedTask); }
public void Remove(ILightAttachment attachment) { _client.DeleteObject(this.Container, attachment.ResourceId + "/" + attachment.Id); }
static void Main() { var demoContent = File.ReadAllBytes(Path.Combine(Environment.CurrentDirectory, "DemoFile.txt")); var storageClient = new StorageClient("5cd104e23fc947668a6c74fe63fd77e7/godbold_1310683369246", "FGJeXUzxCz5poHoSzRzmMTceuek="); var storedObjectResponse = storageClient.CreateObject(new CreateObjectRequest { Content = demoContent, Resource = new Uri("objects", UriKind.Relative), GroupACL = "other=NONE", ACL = "godbold=FULL_CONTROL", Metadata = "part1=buy", ListableMetadata = "part4/part7/part8=quick" }); Console.WriteLine("Object stored at {0}", storedObjectResponse.Location); Console.ReadKey(); var namespaceCreateResponse = storageClient.CreateObject(new CreateObjectRequest { Resource = new Uri("namespace/test/profiles of stuff/", UriKind.Relative), GroupACL = "other=NONE", ACL = "godbold=FULL_CONTROL", Metadata = "part1=buy", ListableMetadata = "part4/part7/part8=quick" }); Console.WriteLine("Namespace created at {0}", namespaceCreateResponse.Location); Console.ReadKey(); var getNamespaceResponse = storageClient.GetObject(new GetObjectRequest { Resource = new Uri(namespaceCreateResponse.Location, UriKind.Relative), }); var namespaceContent = Encoding.ASCII.GetChars(getNamespaceResponse.Content, 0, getNamespaceResponse.Content.Length); var namespaceContentString = new string(namespaceContent); Console.WriteLine("Namespace {0} retrieved", namespaceCreateResponse.Location); Console.WriteLine("Content: {0}", namespaceContentString); Console.ReadKey(); Console.WriteLine("Deleting namespace at {0}", namespaceCreateResponse.Location); storageClient.DeleteObject(new DeleteObjectRequest { Resource = new Uri(namespaceCreateResponse.Location, UriKind.Relative) }); Console.WriteLine("Namespace at {0} deleted", namespaceCreateResponse.Location); Console.ReadKey(); var getFullObjectResponse = storageClient.GetObject(new GetObjectRequest { Resource = new Uri(storedObjectResponse.Location, UriKind.Relative), }); var allContent = Encoding.ASCII.GetChars(getFullObjectResponse.Content, 0, getFullObjectResponse.Content.Length); var allContentString = new string(allContent); Console.WriteLine("Object {0} retrieved", storedObjectResponse.Location); Console.WriteLine("Content: {0}", allContentString); Console.ReadKey(); var getObjectResponse = storageClient.GetObject(new GetObjectRequest { Resource = new Uri(storedObjectResponse.Location, UriKind.Relative), LowerRange = 10 }); var content = Encoding.ASCII.GetChars(getObjectResponse.Content, 0, getObjectResponse.Content.Length); var contentString = new string(content); Console.WriteLine("Object {0} retrieved", storedObjectResponse.Location); Console.WriteLine("Content: {0}", contentString); Console.ReadKey(); Console.WriteLine("Updating object stored at {0}", storedObjectResponse.Location); storageClient.UpdateObject(new UpdateObjectRequest { Resource = new Uri(storedObjectResponse.Location, UriKind.Relative), Content = demoContent }); Console.WriteLine("Object at {0} was updated", storedObjectResponse.Location); Console.ReadKey(); Console.WriteLine("Deleting object stored at {0}", storedObjectResponse.Location); storageClient.DeleteObject(new DeleteObjectRequest { Resource = new Uri(storedObjectResponse.Location, UriKind.Relative) }); Console.WriteLine("Object at {0} deleted", storedObjectResponse.Location); Console.ReadKey(); }
public void Remove(StorageFileId storageFileId) { _storageClient.DeleteObject(_settings.GoogleBucketName, GetObjectName(storageFileId)); }
public void DeleteItem(string objectName) { storageClient.DeleteObject(bucketName, objectName); }
public void DeleteImage(string name) { Storage.DeleteObject(BucketName, name); }
public override void Delete(string path) { _storageClient.DeleteObject(_bucketName, path); }
public Task DeleteAsync(string videoUrl) { return(Task.Run(() => _storage.DeleteObject(BucketName, GetObjectName(videoUrl)) )); }
public void DeleteFileFromGcs(string bucket, string fileName) { StorageClient gcsClient = StorageClient.Create(); gcsClient.DeleteObject(bucket, fileName); }