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: the browser needs to set cross domain and expose the x-oss-next-append-position header #1218

Merged
merged 5 commits into from
Jul 20, 2023
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: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1880,7 +1880,7 @@ object:
- headers {Object} response headers
- size {Number} response size
- rt {Number} request total use time (ms)
- nextAppendPosition {String} the next position
- nextAppendPosition {String} the next position(The browser needs to set cross domain and expose the x-oss-next-append-position header)

example:

Expand Down
35 changes: 35 additions & 0 deletions test/browser/browser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2449,4 +2449,39 @@ describe('browser', () => {
assert.equal(header['x-oss-server-side-encryption'], undefined);
});
});

describe('append()', () => {
const name = `/${prefix}ali-sdk/oss/apend${Date.now()}`;
let store;
before(() => {
store = oss(ossConfig);
});

afterEach(async () => {
await store.delete(name);
});

it('should apend object with content blob', async () => {
let object = await store.append(name, new Blob(['foo']));
const { nextAppendPosition } = object;
assert.strictEqual(object.res.status, 200);
assert.strictEqual(nextAppendPosition, '3');
assert.strictEqual(object.res.headers['x-oss-next-append-position'], '3');

let res = await store.get(name);
assert.strictEqual(res.content.toString(), 'foo');
assert.strictEqual(res.res.headers['x-oss-next-append-position'], '3');

object = await store.append(name, new Blob(['bar']), {
position: nextAppendPosition
});
assert.strictEqual(object.res.status, 200);
assert.strictEqual(object.nextAppendPosition, '6');
assert.strictEqual(object.res.headers['x-oss-next-append-position'], '6');

res = await store.get(name, { subres: { 'response-cache-control': 'no-store' } });
assert.strictEqual(res.content.toString(), 'foobar');
assert.strictEqual(res.res.headers['x-oss-next-append-position'], '6');
});
});
});
20 changes: 10 additions & 10 deletions test/node/object.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2115,24 +2115,24 @@ describe('test/object.test.js', () => {

it('should apend object with content buffer', async () => {
let object = await store.append(name, Buffer.from('foo'));
assert(object.res.status === 200);
assert(object.nextAppendPosition === '3');
assert(object.res.headers['x-oss-next-append-position'] === '3');
assert.strictEqual(object.res.status, 200);
assert.strictEqual(object.nextAppendPosition, '3');
assert.strictEqual(object.res.headers['x-oss-next-append-position'], '3');

let res = await store.get(name);
assert(res.content.toString() === 'foo');
assert(res.res.headers['x-oss-next-append-position'] === '3');
assert.strictEqual(res.content.toString(), 'foo');
assert.strictEqual(res.res.headers['x-oss-next-append-position'], '3');

object = await store.append(name, Buffer.from('bar'), {
position: 3
});
assert(object.res.status === 200);
assert(object.nextAppendPosition === '6');
assert(object.res.headers['x-oss-next-append-position'] === '6');
assert.strictEqual(object.res.status, 200);
assert.strictEqual(object.nextAppendPosition, '6');
assert.strictEqual(object.res.headers['x-oss-next-append-position'], '6');

res = await store.get(name);
assert(res.content.toString() === 'foobar');
assert(res.res.headers['x-oss-next-append-position'] === '6');
assert.strictEqual(res.content.toString(), 'foobar');
assert.strictEqual(res.res.headers['x-oss-next-append-position'], '6');
});

it('should apend object with local file path', async () => {
Expand Down
Loading