-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(dsb-client-gateway-api): file upload with chunk #70
base: develop
Are you sure you want to change the base?
Conversation
|
||
let result: SendMessageResponseFile = null; | ||
if (this.enableUploadChunk) { | ||
const _file = await buffer(fs.createReadStream(filePath)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it will cause high memory consumption as you read whole stream into a buffer - could cause buffer overflow
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup, any suggestion. how encryption handle it ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
streams
https://github.com/dannycho7/split-file-stream
you can use this library - split file to smaller chunks, upload them one by one. Calculate maxFileSize
dynamically using some env. variable
const _buffer = _file.slice(from, to); | ||
//uploading file | ||
result = | ||
await this.ddhubFilesService.uploadFileChunk( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if this fails? do you revert whole file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MB will handle it
stopOnResponseCodes: ['10'], | ||
} | ||
); | ||
if (result.data == "") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if promise is solved it means it was successful - we don't need this check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MB only return 200 status
); | ||
if (result.data == "") { | ||
this.logger.log(`upload chunk ${currentChunkIndex} file with file name: ${originalname}`); | ||
return result.data as SendMessageResponseFile; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why return empty string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that for continue loop chunk
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but it's incorrect - you return empty string without any data while telling this is SendMessageResponseFile
type
clientGatewayMessageId: string, | ||
payloadEncryption: boolean, | ||
transactionId?: string | ||
): Promise<SendMessageResponseFile> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add here | null
|
||
const _data = result.data as SendMessageResponseFile; | ||
if (_data.recipients.failed > 0) { | ||
throw new Error(`upload file with file name: ${originalname} failed`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we really throw an error if 1 recipient received message and second one didn't?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that from existing
|
||
const promise = () => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move it to separate method i.e. uploadChunks
or smth like that
@@ -76,6 +76,84 @@ export class DdhubFilesService extends DdhubBaseService { | |||
} | |||
); | |||
|
|||
const _data = result.data as SendMessageResponseFile; | |||
if (_data.recipients.failed > 0) { | |||
throw new Error(`upload file with file name: ${originalname} failed`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add custom exception for it
}); | ||
await promise(); | ||
} else { | ||
//uploading file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove comment, function name is obvious enough
b4c4a61
to
cd67743
Compare
b5fb9fc
to
6031f1b
Compare
No description provided.