Skip to content

Sending a ZIP file as API call payload #4118

@yorickcleerbout

Description

@yorickcleerbout

Details

Hi guys, i was wondering if anyone could help me out. I'm currently working om some sort of tool that is using API calls, and i need to send a ZIP file as form params to the server. In curl it is using the tags -F "file=@filename.zip" but i was wondering how i can do this with nodejs. I currently have the following code but it gives me a 400 bad request:

let form = new FormData();
        form.append('file', fs.readFileSync(`./apigee/proxies/${file}`));

        let response = await fetch(`${to}/v1/organizations/${torg}/apis?action=import&name=${file.slice(0,-4)}`, {
            method: 'post',
            body: form,
            headers: {'Authorization': `Bearer ${ta}`, 'Content-Type': 'multipart/form-data'}
        });

Node.js version

Not applicable.

Example code

No response

Operating system

Windows

Scope

code

Module and version

Not applicable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions