File tree Expand file tree Collapse file tree 1 file changed +9
-0
lines changed
src/components/file/bucket Expand file tree Collapse file tree 1 file changed +9
-0
lines changed Original file line number Diff line number Diff line change 1
1
import { NoSuchKey , S3 } from '@aws-sdk/client-s3' ;
2
2
import { getSignedUrl } from '@aws-sdk/s3-request-presigner' ;
3
3
import { Type } from '@nestjs/common' ;
4
+ import { bufferFromStream } from '@seedcompany/common' ;
4
5
import { Command } from '@smithy/smithy-client' ;
5
6
import { Duration } from 'luxon' ;
6
7
import { join } from 'path/posix' ;
@@ -59,10 +60,18 @@ export class S3Bucket extends FileBucket {
59
60
}
60
61
61
62
async putObject ( input : PutObjectInput ) {
63
+ // S3 needs to know the content length either from body or the header.
64
+ // Since we streams don't have that, and we don't know from file, we need to
65
+ // buffer it. This way we can know the length to send to S3.
66
+ const fixedLengthBody =
67
+ input . Body instanceof Readable
68
+ ? await bufferFromStream ( input . Body )
69
+ : input . Body ;
62
70
await this . s3 . putObject ( {
63
71
...input ,
64
72
Key : this . fullKey ( input . Key ) ,
65
73
Bucket : this . bucket ,
74
+ Body : fixedLengthBody ,
66
75
} ) ;
67
76
}
68
77
You can’t perform that action at this time.
0 commit comments