當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。