public async Task <BlobInfoV1> CreateBlobFromDataAsync(string correlationId, BlobInfoV1 blob, byte[] buffer) { using (var stream = new MemoryStream(buffer)) { return(await CreateBlobFromStreamAsync(correlationId, blob, stream)); } }
////////// Blobs streaming API ////////// public async Task <string> BeginBlobWriteAsync(string correlationId, BlobInfoV1 item) { CheckOpened(correlationId); item.Id = item.Id ?? IdGenerator.NextLong(); item.Group = EncodeString(item.Group); item.Name = EncodeString(item.Name); var filename = item.Name ?? item.Id + ".dat"; var request = new InitiateMultipartUploadRequest { BucketName = _bucket, Key = item.Id, CannedACL = S3CannedACL.PublicRead, ContentType = item.ContentType, StorageClass = _reducedRedundancy ? S3StorageClass.ReducedRedundancy : S3StorageClass.Standard }; request.Headers.ContentDisposition = "inline; filename=" + filename; if (item.ExpireTime != null) { request.Headers.Expires = item.ExpireTime; } request.Metadata.Add("name", item.Name); request.Metadata.Add("group", item.Group); request.Metadata.Add("completed", StringConverter.ToString(item.Completed)); var result = await _client.InitiateMultipartUploadAsync(request); var token = item.Id + ";" + result.UploadId; return(token); }
public async Task <BlobInfoV1> UpdateBlobInfoAsync(string correlationId, BlobInfoV1 item) { item.Group = EncodeString(item.Group); item.Name = EncodeString(item.Name); var filename = item.Name ?? (item.Id + ".dat"); var request = new CopyObjectRequest { SourceBucket = _bucket, SourceKey = item.Id, DestinationBucket = _bucket, DestinationKey = item.Id, CannedACL = S3CannedACL.PublicRead, ContentType = item.ContentType, StorageClass = _reducedRedundancy ? S3StorageClass.ReducedRedundancy : S3StorageClass.Standard }; request.Headers.ContentDisposition = "inline; filename=" + filename; if (item.ExpireTime != null) { request.Headers.Expires = item.ExpireTime; } request.Metadata.Add("name", item.Name); request.Metadata.Add("group", item.Group); request.Metadata.Add("completed", StringConverter.ToString(item.Completed)); await _client.CopyObjectAsync(request); return(item); }
public async Task <BlobInfoV1> UpdateBlobInfoAsync(string correlationId, BlobInfoV1 blob) { return(await CallCommandAsync <BlobInfoV1>( "update_blob_info", correlationId, new { blob = blob } )); }
////////// Blobs streaming API ////////// public async Task <string> BeginBlobWriteAsync(string correlationId, BlobInfoV1 item) { return(await CallCommandAsync <string>( "begin_blob_write", correlationId, new { blob = item } )); }
public async Task <BlobInfoV1> CreateBlobFromUriAsync(string correlationId, BlobInfoV1 blob, string uri) { var request = WebRequest.Create(uri); var response = request.GetResponse(); using (var stream = response.GetResponseStream()) { blob.ContentType = response.ContentType; blob.Size = response.ContentLength; return(await CreateBlobFromStreamAsync(correlationId, blob, stream)); } }
private bool MatchSearch(BlobInfoV1 item, string search) { search = search.ToLower(); if (MatchString(item.Name, search)) { return(true); } if (MatchString(item.Group, search)) { return(true); } return(false); }
public async Task <BlobInfoV1> GetBlobByIdAsync(string correlationId, string id) { CheckOpened(correlationId); try { var result = await _client.GetObjectMetadataAsync(new GetObjectMetadataRequest { BucketName = _bucket, Key = id }); var item = new BlobInfoV1 { Id = id, Group = DecodeString(result.Metadata["group"]), Name = DecodeString(result.Metadata["name"]), Size = result.ContentLength, ContentType = result.Headers.ContentType, CreateTime = result.LastModified, ExpireTime = result.Headers.Expires, Completed = BooleanConverter.ToBoolean(result.Metadata["completed"]) }; return(item); } catch (AmazonS3Exception ex) { if (ex.ErrorCode == "NotFound") { return(null); } throw; } }
public async Task <BlobInfoV1> CreateBlobFromStreamAsync(string correlationId, BlobInfoV1 blob, Stream stream) { // Generate file id blob.Id = blob.Id ?? IdGenerator.NextLong(); blob.CreateTime = DateTime.UtcNow; // Start writing var token = await _client.BeginBlobWriteAsync(correlationId, blob); // Write in chunks var buffer = new byte[_chunkSize]; while (true) { var size = await stream.ReadAsync(buffer, 0, buffer.Length); if (size == 0) { break; } var chunk = buffer; if (size != buffer.Length) { chunk = new byte[size]; Array.Copy(buffer, 0, chunk, 0, size); // Array.Resize(ref buffer, size); } token = await _client.WriteBlobChunkAsync(correlationId, token, chunk); } // Finish writing and return blobId blob = await _client.EndBlobWriteAsync(correlationId, token, new byte[] { }); return(blob); }
public async Task <BlobInfoV1> CreateBlobFromStreamAsync(string correlationId, BlobInfoV1 blob, Stream stream) { return(await _streamingController.CreateBlobFromStreamAsync(correlationId, blob, stream)); }
public async Task <BlobInfoV1> CreateBlobFromDataAsync(string correlationId, BlobInfoV1 blob, byte[] buffer) { return(await _streamingController.CreateBlobFromDataAsync(correlationId, blob, buffer)); }
public async Task <BlobInfoV1> UpdateBlobInfoAsync(string correlationId, BlobInfoV1 blob) { return(await Task.FromResult(blob)); }
public async Task <BlobInfoV1> CreateBlobFromStreamAsync(string correlationId, BlobInfoV1 blob, Stream stream) { return(await Task.FromResult(blob)); }
public async Task <BlobInfoV1> CreateBlobFromDataAsync(string correlationId, BlobInfoV1 blob, byte[] buffer) { return(await Task.FromResult(blob)); }
public async Task <BlobInfoV1> CreateBlobFromUriAsync(string correlationId, BlobInfoV1 blob, string uri) { return(await Task.FromResult(blob)); }