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

fix: checkpoint.file #795

Merged
merged 1 commit into from
Aug 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/browser/managed-upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ proto.multipartUpload = async function multipartUpload(name, file, options) {
this.resetCancelFlag();
options = options || {};
if (options.checkpoint && options.checkpoint.uploadId) {
if (file && isFile(file)) options.checkpoint.file = file;

return await this._resumeMultipart(options.checkpoint, options);
}

Expand Down
28 changes: 28 additions & 0 deletions test/browser/browser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1154,6 +1154,34 @@ describe('browser', () => {
}
});

it('should multipart upload file with checkpoint', async () => {
const client = store;
// create a file with 1M random data
const fileContent = Array(1024 * 1024).fill('a').join('');
const file = new File([fileContent], 'multipart-upload-file');

const name = `${prefix}multipart/upload-file-checkpoint`;
let checkpoint;
const options = {
async progress(p, _checkpoint) {
if (p > 0.5 && !checkpoint) {
client.resetCancelFlag();
checkpoint = _checkpoint;
}
},
partSize: 100 * 1024,
checkpoint
};
try {
await client.multipartUpload(name, file, options);
} catch (err) {
assert.equal(true, client.isCancel());
}
await client.multipartUpload(name, file, options);
const result = await client.get(name);
assert.equal(result.content.length, 1024 * 1024);
});

it('should upload with uploadPart', async () => {
const fileContent = Array(10 * 100 * 1024).fill('a').join('');
const file = new File([fileContent], 'multipart-upload-part');
Expand Down