Comments (8)
Hm, seems like the request object needs the Content-Length
in order be constructed. Since getting the value for that is async it can't be returned right away. Got an idea for a patch?
from form-data.
We can create request object before async call and return it and populate it later. But I was thinking that it's might be confusing to return httpRequest from FormData, since people might expect it to be same object.
Maybe we'll be better off just translating events.
@visionmedia How are you going track the progress on httpRequest?
from form-data.
unfortunate we can't initialize a node request to return (that I know of at least), emitting an event would be pretty weird, two callbacks is weird. I just wrote submit() with the progress stuff built in but im not sure what would be best in here. hmm yeah aside from an event or second callback I'm not sure
from form-data.
@alexindigo I'm just proxying the .write() to the request with this hack:
var write = req.write;
req.write = function(chunk){
return write.call(this, chunk, function(){
form.emit('progress', chunk, len);
});
};
and later using that to do the actual progress reporting. Maybe if we make that stuff into a little module and just do trackProgress(req).on('progress', re-emit crap here)
we could add it to form-data :s haha, but no point turning it into another request library
from form-data.
How about?
if (params.request) {
request = params.request;
} else {
// https if specified, fallback to http in any other case
if (params.protocol == 'https:') {
// override default port
if (!params.port) options.port = 443;
request = https.request;
} else {
request = http.request;
}
}
request = request(options);
then you can have your own augmented request instantiation function.
from form-data.
Oh, looks like we still can add content-length later:
"The header is still mutable using the setHeader(name, value), getHeader(name), removeHeader(name) API. The actual header will be sent along with the first data chunk or when closing the connection."
But, again, don't you think it will be confusing to return httpRequest from FormData.submit?
from form-data.
I think returning it is the most sensible thing personally, especially since it wont break anyone's apps since it's not returning this
for chaining
from form-data.
@visionmedia @felixge Something like that.
from form-data.
Related Issues (20)
- Published Packages Contain unwanted files HOT 3
- Doesn't play nice with node v18 undici fetch HOT 3
- getHeaders should add content length if known HOT 1
- Passing Uint8Array or Buffer leads to "source.on is not a function" error under Node 18 HOT 1
- Need Help Browser support HOT 3
- Final nail in the coffin HOT 1
- Is there a place to report security issues? HOT 2
- From Data HOT 1
- Is this Library Dead? HOT 1
- "form-data" is vulnerable to request tampering via a crafted filename HOT 1
- FormData is undefind
- FormData is undefind
- FormData class is confused with native FormData class in Chrome HOT 1
- Doesn't work well in node version 18 HOT 3
- any option to Read all the key and value from formdata HOT 1
- How to send an array of pdf files using form-data HOT 5
- How do I get upload progress when I submit??? HOT 1
- Mark package with sideEffects: false
- how to upload multiple files with fields at once with formdata
- Is it possible to cancel a fileupload?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from form-data.