-
-
Notifications
You must be signed in to change notification settings - Fork 683
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
the v3 plan? #635
Comments
const server = http.createServer((req, res) => {
if (req.url === '/api/upload' && req.method.toLowerCase() === 'post') {
stream.pipeline(
req,
new MultipartParser(),
async function* consume(source) {
console.log(source.headers);
for await (const chunk of source) {
console.log('chunk:', chunk.toString('utf-8'), '=====');
yield chunk;
}
},
console.error
);
return;
}
// show a file upload form
res.writeHead(200, { 'content-type': 'text/html' });
res.end(`
<h2>With Node.js <code>"http"</code> module</h2>
<form action="/api/upload" enctype="multipart/form-data" method="post">
<div>Text field title: <input type="text" name="title" /></div>
<div>first name: <input type="text" name="first_name" /></div>
<div>File: <input type="file" name="multipleFiles" multiple="multiple" /></div>
<input type="submit" value="Upload" />
</form>
`);
});
server.listen(3000, () => {
console.log('Server listening on http://localhost:3000 ...');
}); |
It would be nice to have some kind of plugins that handle common use cases when uploading files. Like for example have a plugin to upload a file directly to s3, other to azures cloud blob storage and etc... |
Yup, totally cool. I really like this API. The new year will come with a new design 🎉 I cannot believe that a whole year passed and there's still no v2. ;/ |
We can land something cool in v2 as preparation for v3. Provide additional exports like import formidable from 'formidable';
export default (req, res, options = {}) => {
// the code from AWS example
const form = formidable({
...options,
fileWriteStreamHandler: uploadStream,
});
form.parse(req, () => {
res.writeHead(200);
res.end();
});
return form;
} usage in serverless env (bbut should fix #594 for this to be so clean) import formidableWithAWS from 'formidable/with-aws';
export default (req, res) => {
formidableWithAWS(req, res, { credentials })
} |
As long as it is not included in the default formidable export , I am in favour about adding extensions |
Exactly. Built-in "Extensions" (examples, solutions to common things) is good word. |
@tunnckoCore Is it going to be switched to v3 without a stable v2? |
@songkeys we will have v2 stable in the |
@tunnckoCore What prevents us having a stable v2 so far? I'm willing to contribute. But we need a roadmap and a todo-list for stable v2 first, I think. Currently this repo is lack of active maintenance. And many users are still stuck in the 1.X version. Plans and Ideas? |
After #689 is merged I will open another PR for the filter branch. Ideally we fix: the few failing tests (may require some deep untangling of code) |
Ah, I guess the current state of v2 is recorded over here, I'll ask over there: #718 |
One one the first thing I want to do is nodejs/node#38231, |
I created a 3.x branch and opened its first PR for ES Modules |
@tunnckoCore about your first comment first example, I think it is confusing that the pipeline function returns a promise and not a stream. Also it would have the same name as stream.pipeline. In the second example something is out of order: formidable reads request content type to chose the correct parser: json multipart etc. but in your example the parser is chosen before. What we could do is make the formidable function return a promise if no callback is provided, or make it promisable (is that even a word 🥇 ?) with https://nodejs.org/api/util.html#util_custom_promisified_functions . |
This comment has been minimized.
This comment has been minimized.
3.x is already ESM only |
Think there are som bugs in 3.x that needs to be addressed first... the test didn't run so well... Dump
|
One day I tried to make all the test pass but I didn't finish, I 'll have a look this evening again |
When do we publish v3 as latest ? |
I suggest somewhere in December or January. Lets give some time to see how it goes. (i will edit the things now as to #769, what to finish it as quick as possible cuz a lot of people we see PRs so it should be clear) |
@songkeys @jimmywarting check #769 and the comments from today in #718. I'm back, i guess. Interested in crypto more and more so i need dev environment and will be on github more. I seen they launched Codespaces publicly, I should try it tho. |
Crypto Hodl gang ! Codespace is visual studio in the cloud, pretty cool I used something similar hacked together in 2015, neat for multi user collaboration |
Haha, totally... for both. |
the devDep seems a bit outdated, update them? |
Somebody should do it ... |
@jimmywarting meh, they are okay, especially as I didn't look on latest updates on Prettier and Airbnb, just check ESLint 7 before some weeks/months. Jest is usually not that breaking too so. |
Read this https://www.theregister.com/2018/11/26/npm_repo_bitcoin_stealer/ For me the biggest question is not if it is compatible, but if it looks good (including sub dependencies) |
@GrosSacASac that's old, is there some recent things like that? But yea, got it, we should stay updated, true. There's dependabot PRs, but the automerge isn't working for some reason or isn't enabled. That would be the best. |
I KNow it is old but it could happen again, |
I like the FormData and Blob ideas. But whatever we do, we really need to make benchmarks first. Everything boils down to that, otherwise there's no sense in Formidable. Why it exists in the first place. It used to be one of the fastest streaming multipart parsers, and that is at its core. With all the recent Nodejs versions, updates, new standards and all, the question comes more and more. And is it fast at all, with the new Streams APIs. Working in blind isn't good. From what I understand, and from @jimmywarting's examples, I think we should make the following: Initialize formidable/src/plugins/multipart.js Line 51 in 81dd350
and on Right? Then just wrap that and expose or fd.append('file', {
size: part.size,
type: part.mimetype,
name: part.name,
stream() { return part },
[Symbol.toStringTag]: 'File'
}) something like this const form = formidable({ uploadDir: "./uploads" });
const formData = await form.parse(req);
// extension/utility that write files to disk,
for (const [, file] of formData.entries()) {
file.stream().pipe(fs.createWriteStream(file.name));
} quite not right to me tho, but that's userland |
@jimmywarting ha, didn't knew that The only difference is that it's not Transform stream and uses uint8array. Seems like it also expose Do you mind to extract it as |
pipeline(...streams, (err) => {})
multipart/*
?Readable.from(multipart())
?VFile
orVinyl
? v2?Okay, some thoughts.
I think we can just wrap the Node's
stream.pipeline()
and provide it to our users, but they still will be able to do whatever they want, using the Node'spipeline()
. Something like thisThe text was updated successfully, but these errors were encountered: