Phase 3
This commit is contained in:
parent
9321f5a370
commit
25c2ce53cd
23 changed files with 1746 additions and 68 deletions
|
|
@ -34,6 +34,9 @@ public class ObjectStorageService : IObjectStorageService
|
|||
|
||||
public async Task PutAsync(string bucket, string key, Stream content, string contentType, CancellationToken ct = default)
|
||||
{
|
||||
// จับความยาวไว้ก่อน — AWSSDK 4.x dispose input stream ให้หลัง upload เสร็จ อ่าน .Length ตอนหลังไม่ได้
|
||||
long? length = content.CanSeek ? content.Length : null;
|
||||
|
||||
var request = new PutObjectRequest
|
||||
{
|
||||
BucketName = bucket,
|
||||
|
|
@ -41,14 +44,14 @@ public class ObjectStorageService : IObjectStorageService
|
|||
InputStream = content,
|
||||
ContentType = contentType,
|
||||
};
|
||||
if (content.CanSeek)
|
||||
if (length.HasValue)
|
||||
{
|
||||
// ระบุความยาวชัดๆ ไม่ต้องให้ SDK ไป buffer ทั้ง stream
|
||||
request.Headers.ContentLength = content.Length;
|
||||
request.Headers.ContentLength = length.Value;
|
||||
}
|
||||
|
||||
await _s3.PutObjectAsync(request, ct);
|
||||
_logger.LogInformation("Uploaded object {Bucket}/{Key} ({Length} bytes)", bucket, key, content.Length);
|
||||
_logger.LogInformation("Uploaded object {Bucket}/{Key} ({Length} bytes)", bucket, key, length);
|
||||
}
|
||||
|
||||
public async Task<Stream> GetStreamAsync(string bucket, string key, CancellationToken ct = default)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue