Skip to content

Commit

Permalink
feat(rxFileUpload): add new fields in chunkData + update File instanc…
Browse files Browse the repository at this point in the history
…e for chunk binary with the same values than chunkData
  • Loading branch information
akanass committed May 27, 2021
1 parent ede886e commit 8d703ac
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/lib/rx-file-upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
RxFileUploadAdditionalFormData,
RxFileUploadBodyData,
RxFileUploadChunkBodyData,
RxFileUploadChunkData,
RxFileUploadChunkFormData,
RxFileUploadChunkSequenceData,
RxFileUploadChunkSize,
Expand Down Expand Up @@ -126,6 +127,13 @@ export class RxFileUploadCls implements RxFileUpload {
* @internal
*/
private readonly _useChunks: boolean = false;
/**
* Property to store default mime type for a chunk
*
* @private
* @internal
*/
private readonly _chunkMimeType: string = 'application/octet-stream';
/**
* Property to store flag to know if progress Observable will complete at the end of the upload process
*
Expand Down Expand Up @@ -691,15 +699,22 @@ export class RxFileUploadCls implements RxFileUpload {
data: {
...fileData,
chunkData: this._serialize({
name: `${file.name}.part${index + 1}`,
size: _.endByte - _.startByte,
lastModified: file.lastModified,
type: this._chunkMimeType,
sequence: index + 1,
totalChunks: chunkSizes.length,
startByte: _.startByte,
endByte: _.endByte,
}),
} as RxFileUploadChunkData),
file: new File(
[file.slice(_.startByte, _.endByte)],
file.name,
{ type: file.type },
`${file.name}.part${index + 1}`,
{
type: this._chunkMimeType,
lastModified: file.lastModified,
},
),
},
formData: new FormData(),
Expand Down
15 changes: 15 additions & 0 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,18 @@ export type RxFileUploadFileData = {
type: string;
sha256Checksum?: string;
};

/**
* ChunkData type definition
*
* @internal
*/
export type RxFileUploadChunkData = Omit<
RxFileUploadFileData,
'sha256Checksum'
> & {
sequence: number;
totalChunks: number;
startByte: number;
endByte: number;
};

0 comments on commit 8d703ac

Please sign in to comment.