当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript form-data.append函数代码示例

本文整理汇总了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)
  }
开发者ID:mirego,项目名称:accent-cli,代码行数:27,代码来源:document.ts

示例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');
  });
开发者ID:syaiful6,项目名称:jonggrang,代码行数:11,代码来源:error-handling.ts

示例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');
  });
开发者ID:syaiful6,项目名称:jonggrang,代码行数:11,代码来源:file-filter.ts

示例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');
  });
开发者ID:syaiful6,项目名称:jonggrang,代码行数:12,代码来源:disk-storage.ts

示例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'
    });
  });
开发者ID:syaiful6,项目名称:jonggrang,代码行数:14,代码来源:form-fields.ts

示例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);
});
开发者ID:sindresorhus,项目名称:got,代码行数:15,代码来源:progress.ts


注:本文中的form-data.append函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。