开发者

Missing "content-type". I'm using busboy and jest for testing purposes

import { uploadFile } from "../../src/handler";
import { APIGatewayRequest } from "../eventGenerator";
import FormData from "form-data";
import fs from "fs";

export const uploadfile = () => {
  it("Upload File", async () => {
    const filePath = fs.createReadStream("../image/hulk.PNG");
    const formData = new FormData();

    formData.append("file", filePath);
    formData.开发者_JAVA百科append("Title", "Jesting");
    formData.append("Description", "JestingJest");
    formData.append("Editor", "Jester");

    console.log(formData);

    const event = APIGatewayRequest({
      body: formData,
      method: "",
      path: "",
      queryStringObject: "",
      pathParametersObject: "",
      stageVariables: null,
    });

    const test = await uploadFile(event);
    expect(test.statusCode).toBe(201);
  }, 50000);
};

//////////////////////////////////////////////////////////////////////

  ...const request: APIGatewayProxyEvent = {
    body: body ? JSON.stringify(body) : null,
    headers: {
      "for-coop-id": "test",
      "content-type": "multipart/form-data",
      // "Access-Control-Allow-Origin": "*",
    },...

I did change content-type from all-caps it did not change a thing. I tried putting boundaries and removing content-type. Hope you could help.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜