Skip to content
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

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

azam-ismail
Copy link
Contributor

No description provided.

@azam-ismail azam-ismail requested a review from hejkerooo July 7, 2022 08:58

let result: SendMessageResponseFile = null;
if (this.enableUploadChunk) {
const _file = await buffer(fs.createReadStream(filePath));
Copy link
Collaborator

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

Copy link
Contributor Author

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 ?

Copy link
Collaborator

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(
Copy link
Collaborator

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?

Copy link
Contributor Author

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 == "") {
Copy link
Collaborator

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

Copy link
Contributor Author

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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why return empty string?

Copy link
Contributor Author

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

Copy link
Collaborator

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

@azam-ismail azam-ismail requested a review from hejkerooo July 8, 2022 09:38
clientGatewayMessageId: string,
payloadEncryption: boolean,
transactionId?: string
): Promise<SendMessageResponseFile> {
Copy link
Collaborator

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`);
Copy link
Collaborator

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?

Copy link
Contributor Author

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 = () =>
Copy link
Collaborator

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`);
Copy link
Collaborator

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
Copy link
Collaborator

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

@CLAassistant
Copy link

CLAassistant commented Sep 27, 2022

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants