Coder Social home page Coder Social logo

Comments (5)

PaganMuffin avatar PaganMuffin commented on August 29, 2024

Looks like .append() method from formdata-node (v2.5.0) is expecting Blob, Stream or Buffer for data (second argument) but @mrbbot/node-fetch is passing a string.
node-fetch: https://github.com/mrbbot/node-fetch/blob/master/src/body.js#L267
formdata-node (branch 2.x): https://github.com/octet-stream/form-data/blob/2.x/lib/FormData.js#L285

from miniflare.

mrbbot avatar mrbbot commented on August 29, 2024

Hey! 👋 For the next major version of Miniflare, the FormData implementation will come from undici, which should be more spec-compliant. I'll make sure I've got tests for file uploads too. 👍

from miniflare.

octet-stream avatar octet-stream commented on August 29, 2024

I don't think undici will solve this problem. The error seem to appear because you pass a file as a string, but the filename argument can only be used with File or Blob. You need to fix the way how you upload files from what you get with busboy.

Browsers will throw you same error when the third argument is set and the second is a string:

Details

image

from miniflare.

octet-stream avatar octet-stream commented on August 29, 2024

They don't even have FormData parser in their BodyMixin as of now: https://github.com/nodejs/undici/blob/68a17943f4d6af5f27d36ab10471f5e8860a1ede/lib/fetch/body.js#L307-L309

The problem can be solved if you just convert files payload into Blob or File and set the right arguments for each type of the value. You can just upgrade formdata-node to latest version or use fetch-blob (in case if you don't need CJS) to get both of these classes.


For latest formdata-node you'll also need to include a multipart/form-data encoder into your node-fetch fork, such as form-data-encoder because node-fetch does not include one in v2 (v3 does and it even will have form-data parser when this PR will be merged)

from miniflare.

mrbbot avatar mrbbot commented on August 29, 2024

Hey! 👋 The first pre-release of Miniflare 2 has just been released, including support for the formdata_parser_supports_files compatibility flag. Without the flag, uploaded files will be treated as regular string fields. You can find the full changelog here and install it with npm i miniflare@next -D. Please let me know if you have any other issues, and feel free to ask questions in the #miniflare channel of the Cloudflare Workers Discord server.

from miniflare.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.