本文整理匯總了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);
});