@@ -3,11 +3,12 @@ import {
3
3
PutObjectCommand as PutObject ,
4
4
} from '@aws-sdk/client-s3' ;
5
5
import { Injectable } from '@nestjs/common' ;
6
- import { bufferFromStream , cleanJoin } from '@seedcompany/common' ;
6
+ import { bufferFromStream , cleanJoin , Nil } from '@seedcompany/common' ;
7
7
import { Connection } from 'cypher-query-builder' ;
8
8
import { fileTypeFromStream } from 'file-type' ;
9
9
import { intersection } from 'lodash' ;
10
10
import { Duration } from 'luxon' ;
11
+ import mime from 'mime' ;
11
12
import sanitizeFilename from 'sanitize-filename' ;
12
13
import { Readable } from 'stream' ;
13
14
import {
@@ -278,6 +279,8 @@ export class FileService {
278
279
'Only files and directories can be parents of a file version' ,
279
280
) ;
280
281
282
+ const name = await this . resolveName ( undefined , input ) ;
283
+
281
284
if ( uploadingFile ) {
282
285
const prevExists = uploadIdInput
283
286
? await this . bucket . headObject ( uploadId ) . catch ( ( e ) => {
@@ -293,15 +296,20 @@ export class FileService {
293
296
) ;
294
297
}
295
298
const file = await uploadingFile ;
296
- const type = await fileTypeFromStream ( file . createReadStream ( ) ) ;
299
+
300
+ let type : string | Nil = file . mimetype ;
301
+ type = type === 'application/octet-stream' ? null : type ;
302
+ type ??= ( await fileTypeFromStream ( file . createReadStream ( ) ) ) ?. mime ;
303
+ type ??= mime . getType ( name ) ;
304
+ type ??= 'application/octet-stream' ;
305
+
297
306
await this . bucket . putObject ( {
298
307
Key : `temp/${ uploadId } ` ,
299
- ContentType : type ?. mime ?? file . mimetype ,
308
+ ContentType : type ,
300
309
ContentEncoding : file . encoding ,
301
310
Body : file . createReadStream ( ) ,
302
311
} ) ;
303
312
}
304
- const name = await this . resolveName ( undefined , input ) ;
305
313
306
314
const [ tempUpload , existingUpload ] = await Promise . allSettled ( [
307
315
this . bucket . headObject ( `temp/${ uploadId } ` ) ,
0 commit comments