本文整理汇总了TypeScript中form-data.append函数的典型用法代码示例。如果您正苦于以下问题:TypeScript append函数的具体用法?TypeScript append怎么用?TypeScript append使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了append函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: addTranslations
public async addTranslations(
file: string,
language: string,
documentPath: string,
options: any
) {
const formData = new FormData()
formData.append('file', fs.createReadStream(file))
formData.append('document_path', documentPath)
formData.append('document_format', this.config.format)
formData.append('language', language)
let url = `${this.apiUrl}/add-translations`
if (!options.write) url = `${url}/peek`
if (options['merge-type']) {
formData.append('merge_type', options['merge-type'])
}
const response = await fetch(url, {
body: formData,
headers: this.authorizationHeader(),
method: 'POST'
})
return this.handleResponse(response, options, OperationName.AddTranslation)
}
示例2: it
it('should respect field count limit', async function () {
const middleware = mutter({ limits: { fields: 1 } });
const form = new FormData();
form.append('title', 'hello');
form.append('desc', 'hello world');
const result = await T.toPromise(T.attempt(submitForm(middleware, form)));
assert.ok(isLeft(result));
assert.equal((result.value as any).code, 'LIMIT_FIELD_COUNT');
});
示例3: it
it('should skip some files', async function () {
const form = new FormData();
const upload = withFilter(skipFileName);
form.append('notme', file('tiny0.json'));
form.append('butme', file('tiny1.json'));
const { state }: W.HttpContext = await T.toPromise(submitForm(upload, form));
assert.equal(state.files['notme'], undefined);
assert.equal(state.files['butme'][0].fieldname, 'butme');
assert.equal(state.files['butme'][0].originalname, 'tiny1.json');
});
示例4: it
it('should process parser/form-data POST request', async function () {
const middleware = mutter({ getStorage });
const form = new FormData();
form.append('name', 'thatiq');
form.append('tiny0', file('tiny0.json'));
const { state } = await T.toPromise(submitForm(middleware, form));
assert.equal(state.body.name, 'thatiq');
assert.equal(state.files['tiny0'][0].fieldname, 'tiny0');
assert.equal(state.files['tiny0'][0].originalname, 'tiny0.json');
});
示例5: it
it('should process multiple fields', async function () {
const form = new FormData();
form.append('name', 'foo');
form.append('key', 'value');
form.append('abc', 'xyz');
const { state }: W.HttpContext = await T.toPromise(submitForm(middleware, form));
assert.deepEqual(state.body, {
name: 'foo',
key: 'value',
abc: 'xyz'
});
});
示例6: test
test('upload progress - form data', withServer, async (t, server, got) => {
server.post('/', uploadEndpoint);
const events = [];
const body = new FormData();
body.append('key', 'value');
body.append('file', file);
const size = await promisify(body.getLength.bind(body))();
await got.post({body}).on('uploadProgress', event => events.push(event));
checkEvents(t, events, size);
});