Example #1
0
        public async Task WriteAsync(string name, Stream data, CancellationToken cancellationToken)
        {
            if (_storageClient is null)
            {
                var storageClient = await _storageClientFactory.Create();

                Interlocked.CompareExchange(ref _storageClient, storageClient, null);
                if (!ReferenceEquals(_storageClient, storageClient))
                {
                    storageClient.Dispose();
                }
            }

            var obj = await _storageClient !.UploadObjectAsync(
                bucket: _options.BucketName,
                objectName: name,
                contentType: "application/octet-stream",
                source: data,
                options: new UploadObjectOptions {
                PredefinedAcl = PredefinedObjectAcl.PublicRead
            },
                cancellationToken: cancellationToken);

            _logger.LogInformation("Symbol {name} with {length} length stored {link}", name, data.Length, obj.MediaLink);
        }
        public async Task WriteAsync(string name, Stream data, CancellationToken cancellationToken)
        {
            if (_storageClient is null)
            {
                var storageClient = await _storageClientFactory.Create();

                Interlocked.CompareExchange(ref _storageClient, storageClient, null);
                if (!ReferenceEquals(_storageClient, storageClient))
                {
                    storageClient.Dispose();
                }
            }

            try
            {
                var obj = await _storageClient !.UploadObjectAsync(
                    bucket: _options.BucketName,
                    objectName: name,
                    contentType: "application/octet-stream",
                    source: data,
                    options: new UploadObjectOptions {
                    PredefinedAcl = PredefinedObjectAcl.PublicRead
                },
                    cancellationToken: cancellationToken);

                _logger.LogInformation("Symbol {name} with {length} length stored {link}", name, data.Length, obj.MediaLink);
            }
            catch (GoogleApiException e)
            {
                SentrySdk.ConfigureScope(s =>
                {
                    s.Contexts["google-api-error"] = e.Error;
                    s.SetExtra("google-error-service-name", e.ServiceName);
                    s.SetExtra("google-error-status-code", e.HttpStatusCode);
                });
                throw;
            }
        }