public async Task <MemoryStream> DownloadObjectFromBucketAsync(string objectName) { var memoryStream = new MemoryStream(); await _storageClient.DownloadObjectAsync(_configuration.TraceAggregatorBucketName, objectName, memoryStream); return(memoryStream); }
private async Task <BlobData> GetLatestDataAsync(StorageClient storageClient) { // Set the appropriate AccessCondition based on what we believe the latest // file contents to be, then make the request. var latestCachedData = Volatile.Read(ref _cachedBlobData); // local ref so field isn't mutated under our feet try { using (var memoryStream = new MemoryStream()) { var obj = await storageClient.GetObjectAsync(_bucketName, _name); await storageClient.DownloadObjectAsync(obj, memoryStream); latestCachedData = new BlobData() { BlobContents = memoryStream.ToArray(), ETag = obj.ETag }; } Volatile.Write(ref _cachedBlobData, latestCachedData); } catch { latestCachedData = null; Volatile.Write(ref _cachedBlobData, latestCachedData); } return(latestCachedData); }
public async Task DownloadFileAsync(string bucket, string objectName, Stream destination) { using (StorageClient client = await StorageClient.CreateAsync(_credential)) { await client.DownloadObjectAsync(bucket, objectName, destination); } }
public async Task <IActionResult> Index() { var model = new HomeIndex(); if (new string[] { null, "", "your-google-bucket-name" } .Contains(_options.BucketName)) { model.MissingBucketName = true; return(View(model)); } try { var storageObject = await _storage.GetObjectAsync(_options.BucketName, _options.ObjectName); model.MediaLink = storageObject.MediaLink; MemoryStream m = new MemoryStream(); await _storage.DownloadObjectAsync( _options.BucketName, _options.ObjectName, m); m.Seek(0, SeekOrigin.Begin); byte[] content = new byte[m.Length]; m.Read(content, 0, content.Length); model.Content = Encoding.UTF8.GetString(content); } catch (GoogleApiException e) when(e.HttpStatusCode == System.Net.HttpStatusCode.NotFound) { // Does not exist yet. No problem. } return(View(model)); }
public static async Task <Stream> DownloadStreamFromStorageAsync(StorageClient storageClient, Google.Apis.Storage.v1.Data.Object storageObject) { MemoryStream memoryStream = new MemoryStream(); await storageClient.DownloadObjectAsync(storageObject, memoryStream); memoryStream.Position = 0; return(memoryStream); }
public async Task <string> ReadAsync(string path) { using var outputFile = File.OpenWrite("temp-path"); // TODO: "bucket-name", "object-name" - get from 'path' await _storage.DownloadObjectAsync("bucket-name", "object-name", outputFile); return(await _fileStreamService.ReadAsync("temp-path")); }
public async Task <Stream> DownloadAsync(string fileName) { var stream = new MemoryStream(); await _storageClient.DownloadObjectAsync(_gcpStorageConfig.BucketName, fileName, stream); return(stream); }
public async void DownloadMarketDataFile(string googleFilePathname, string newFilePathname) { FileStream stream = File.OpenWrite(newFilePathname); CloudDownloadProgress newProgress = new CloudDownloadProgress(googleFilePathname); await _storageClient.DownloadObjectAsync(_marketDataStorageBucketName, googleFilePathname, stream, null, default(System.Threading.CancellationToken), newProgress); }
public ConfiguredTaskAwaitable DownloadObjectAsync(string fileName, Stream stream) { return(_client.DownloadObjectAsync( _bucketName, fileName, cancellationToken: CancellationToken, destination: stream ).ConfigureAwait(false)); }
public async Task <Stream> RetrieveFile(string identifier) { var stream = new MemoryStream(); await _googleClient.DownloadObjectAsync(GoogleSettings.Bucket, identifier, stream); stream.Position = 0; return(stream); }
public async Task <byte[]> Read(string fileName) { using (MemoryStream stream = new MemoryStream()) { await _storageClient.DownloadObjectAsync(_bucketName, fileName, stream); return(stream.ToArray()); } }
public async Task DownloadFile(string fileName, string downloadLocation) { try { var absoluteFileLocation = Path.GetFullPath(downloadLocation); await using var objectStream = File.OpenWrite(@$ "{absoluteFileLocation}\{fileName}"); Console.WriteLine($"Descarcam fisierul {fileName} in {downloadLocation}..."); await _storageClient.DownloadObjectAsync(_bucketName, fileName, objectStream); }
public async Task <string> DownloadFileAsync(string blobName) { var path = $"{DownloadPath}/{blobName}"; using var outputFile = File.OpenWrite(path); await StorageClient.DownloadObjectAsync(BucketName, blobName, outputFile); return(path); }
public async Task <byte[]> GetFile(string identificator) { var stream = new MemoryStream(); await _storageClient.DownloadObjectAsync( bucket : _bucketName, objectName : identificator, destination : stream ); return(stream.ToArray()); }
public async Task <IActionResult> GetWithBranch(string branch, string version, string filename) { using (var stream = new MemoryStream()) { await storageClient.DownloadObjectAsync("upward-test", $"pkg/{Response.Headers["x-project-id"]}/{branch}/{version}/{filename}", stream); var metaData = await storageClient.GetObjectAsync("upward-test", $"pkg/{Response.Headers["x-project-id"]}/{branch}/{version}/{filename}"); return(File(stream.ToArray(), metaData.ContentType)); } }
private static async Task DownloadObject(StorageClient client, string bucket, string source, string destination) { using (var output = File.Create(destination)) { var progress = new Progress <IDownloadProgress>( p => Console.WriteLine($"Downloaded {p.BytesDownloaded} bytes; status: {p.Status}")); await client.DownloadObjectAsync(bucket, source, output, new DownloadObjectOptions { ChunkSize = 256 * 1024 }, CancellationToken.None, progress); } }
public async Task <byte[]> GetBlob(Uri key) { var bucket = GetBucketName(key); var blob = GetObjectName(key); using (var stream = new MemoryStream()) { await _client.DownloadObjectAsync(bucket, blob, stream); return(stream.ToArray()); } }
public async Task <Game> GetGame(string name) { var source = await _storageClient.GetObjectAsync(BucketName, name); using (var ms = new MemoryStream()) { await _storageClient.DownloadObjectAsync(source, ms); var json = Encoding.UTF8.GetString(ms.ToArray()); return(JsonConvert.DeserializeObject <Game>(json)); } }
public async Task <string> ReadAllAsync(string path) { var stream = new MemoryStream(); await _googleStorageClient.DownloadObjectAsync(_bucket, path, stream); await stream.FlushAsync(); stream.Seek(0, SeekOrigin.Begin); var streamReader = new StreamReader(stream); var result = await streamReader.ReadToEndAsync(); return(result); }
public async Task DownloadAsync(string id, long version, string suffix, Stream stream) { var objectName = GetObjectName(id, version, suffix); try { await storageClient.DownloadObjectAsync(bucketName, objectName, stream); } catch (GoogleApiException ex) when(ex.HttpStatusCode == HttpStatusCode.NotFound) { throw new AssetNotFoundException($"Asset {id}, {version} not found.", ex); } }
public async Task DownloadAsync(string id, long version, string suffix, Stream stream, CancellationToken ct = default(CancellationToken)) { var objectName = GetObjectName(id, version, suffix); try { await storageClient.DownloadObjectAsync(bucketName, objectName, stream, cancellationToken : ct); } catch (GoogleApiException ex) when(ex.HttpStatusCode == HttpStatusCode.NotFound) { throw new AssetNotFoundException($"Id={id}, Version={version}", ex); } }
public async Task DownloadAsync(string fileName, Stream stream, CancellationToken ct = default) { Guard.NotNullOrEmpty(fileName, nameof(fileName)); try { await storageClient.DownloadObjectAsync(bucketName, fileName, stream, cancellationToken : ct); } catch (GoogleApiException ex) when(ex.HttpStatusCode == HttpStatusCode.NotFound) { throw new AssetNotFoundException(fileName, ex); } }
public async Task <IActionResult> Process(Payload payload) { if (payload?.Message == null) { _logger.LogError("Payload is NULL"); return(BadRequest()); } var fighterName = Encoding.UTF8.GetString(Convert.FromBase64String(payload.Message.Data)); var rankName = $"rank-{random.Next(1, 13)}.png"; _logger.LogInformation($"Associating {fighterName} with rank {rankName}"); var rankFile = new MemoryStream(); var fighterFile = new MemoryStream(); await _storage.DownloadObjectAsync(_config.RanksBucketName, rankName, rankFile); await _storage.DownloadObjectAsync(_config.FightersBucketName, fighterName, fighterFile); var image = Combine(fighterFile, rankFile); using (SKData encoded = image.Encode(SKEncodedImageFormat.Png, 100)) using (Stream outFile = new MemoryStream()) { encoded.SaveTo(outFile); await _storage.UploadObjectAsync(_config.FightersBucketName, fighterName, "image/png", outFile, new UploadObjectOptions { PredefinedAcl = PredefinedObjectAcl.PublicRead }); } return(Accepted()); }
public async Task <ILightAttachment> GetAsync(string resourceId, string id) { Stream stream = new MemoryStream(); await _client.DownloadObjectAsync(this.Container, resourceId + "/" + id, stream); LightAttachment _blob = new LightAttachment() { MediaStream = stream, Id = id, ResourceId = resourceId, ContentType = MimeMapping.MimeUtility.GetMimeMapping(id), Name = id }; return(_blob); }
public async Task <Stream> GetBlobStreamAsync(string containerName, string blobName) { try { var stream = new MemoryStream(); await _client.DownloadObjectAsync(_bucket, ObjectName(containerName, blobName), stream); stream.Seek(0, SeekOrigin.Begin); return(stream); } catch (GoogleApiException gae) { throw Error(gae); } }
public async Task DownloadAsync(string bucket, string source, string destination, IProgress <IDownloadProgress> progress) { try { using (var stream = new FileStream(destination, FileMode.Create)) { await _client.DownloadObjectAsync(bucket, source, stream, progress : progress); } } catch (GoogleApiException e) { // TODO: add exception code check Console.WriteLine(e); throw; } }
public async Task <Stream> OpenReadAsync(IUnixFileEntry fileEntry, long startPosition, CancellationToken cancellationToken) { var gcsFileEntry = (GcsFileEntry)fileEntry; try { var ms = new MemoryStream(); await _storageClient.DownloadObjectAsync(_bucketName, gcsFileEntry.FullName, ms, null, cancellationToken); var data = ms.ToArray().Skip(Convert.ToInt32(startPosition)).ToArray(); ms = new MemoryStream(data); return(ms); } catch { return(null); } }
public Stream DownloadObject(string fileName) { var stream = new EchoStream(maxQueueDepth: 32) { ReadTimeout = (int)TimeSpan.FromSeconds(100).TotalMilliseconds }; stream.TaskToWatch(_client.DownloadObjectAsync( _bucketName, fileName, destination: stream, new DownloadObjectOptions { ChunkSize = (int)DownloadChunkSize.GetValue(SizeUnit.Bytes) }, cancellationToken: CancellationToken)); return(stream); }
public async Task DownloadAsync(string fileName, Stream stream, BytesRange range = default, CancellationToken ct = default) { Guard.NotNullOrEmpty(fileName); try { var downloadOptions = new DownloadObjectOptions(); if (range.IsDefined) { downloadOptions.Range = new RangeHeaderValue(range.From, range.To); } await storageClient.DownloadObjectAsync(bucketName, fileName, stream, downloadOptions, ct); } catch (GoogleApiException ex) when(ex.HttpStatusCode == HttpStatusCode.NotFound) { throw new AssetNotFoundException(fileName, ex); } }
public override async Task <Stream> OpenReadAsync(string fullPath, CancellationToken cancellationToken = default) { GenericValidation.CheckBlobFullPath(fullPath); fullPath = NormalisePath(fullPath); // no read streaming support in this crappy SDK var ms = new MemoryStream(); try { await _client.DownloadObjectAsync(_bucketName, fullPath, ms, cancellationToken : cancellationToken).ConfigureAwait(false); } catch (GoogleApiException ex) when(ex.HttpStatusCode == HttpStatusCode.NotFound) { return(null); } ms.Position = 0; return(ms); }