Skip to content

Doesn't work either with latest stable and beta version of node-fetch #94

Closed
@octet-stream

Description

@octet-stream

@jimmywarting As I mentioned here, I'm running into the problem when using this package with node-fetch. The problem remains both in the latest stable and beta. With fetch-blob@3.0.0-rc.0 and fetch-blob@2.1.1.

I was trying to test an example for my form-data-encoder where the encoder targeting Blob as you did in formdata-polyfill:

import {Readable} from "stream"

import {FormData, fileFromPath} from "formdata-node"
import {Encoder} from "form-data-encoder"

import Blob from "fetch-blob"
import fetch from "node-fetch"

async function toBlob(form) {
  const encoder = new Encoder(form)
  const chunks = []

  for await (const chunk of encoder) {
    chunks.push(chunk)
  }

  return new Blob(chunks, {type: encoder.contentType})
}

const fd = new FormData()

fd.set("name", "John Doe")
fd.set("avatar", await fileFromPath("avatar.png"))

const options = {
  method: "post",
  body: await toBlob(fd)
}

const response = await fetch("https://httpbin.org/post", options)

console.log(await response.text())

When I run this code node test.mjs this happens:

  1. With fetch-blob I get the following error: body.stream().pipe(dest);. This error appears in node-fetch/src/body.js:374:17
  2. When I run the same code, but with fetch-blob@2.1.1 it will lowercase the value of Blob#type which breaks boundary string returned by form-data-encoder.

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