Comments (8)
Hey @tomas , I would love to have this feature. Yesterday I was all day changing my app from request to needle and I could do everything but this. I really need to know at least the bytes transferred while I'm uploading a file. I tried to do something like this (when I was using request it worked), but req.request.connection._bytesDispatched
always returns the same value:
var stats = jetpack.inspect(file.path)
var needleFile = {
buffer: jetpack.read(file.path, 'buffer'),
content_type: file.type,
filename: file.name
}
var data = {
parent_id: parentId,
file: needleFile
}
var options = {
follow: 3,
multipart: true
}
var req = needle.post(fileUploadUrl, data, options,
function(err, resp, body) {
clearTimeout(pooler)
if (resp.statusCode == 201) {
console.log(body)
} else {
console.log(resp.statusCode, resp.statusMessage)
}
})
var pooler = setInterval(() => {
pCb({
percentage: Math.floor(req.request.connection._bytesDispatched * 100 / stats['size']),
eta: ''
})
}, 500)
Also I tried using req.on('data', ...
but it didn't work. Is there any way to get the progress state when uploading?
Thank you!
from needle.
You mean from the command line or through your app?
from needle.
My app is a shell app, i want to show a progressbar in my shell like this
############################################################## 100.0%
but how ?
Ho can I check how much bytes I've sent to my server ?
from needle.
Currently you can't. I suppose you could fork the repo and trigger an event whenever a chunk of data is sent, so you can calculate the percentage done vs remaining.
from needle.
Damn, I saw that: https://github.com/IndigoUnited/node-request-progress but this is for request modules.
Dammit.
from needle.
Looks like that library is for tracking download progress, not upload progress. For downloads I think that same library might be used with Needle as it is. Just replace the request
call with needle
and it should work.
from needle.
You right but I want to show upload progressbar, damn.
So, Can I detect chuck of data sent using needle.post?
It's I think the right way to me.
from needle.
Shoot I totally forgot about this, sorry mate.
If you're using a recent version of node, you should be able to set a listener on the returned object (which is the response stream). Something like:
var req = needle.post('http://foo.com/bar', { data: 'bla' }, function(err, resp) {
console.log('Request finished');
});
req.on('data', function(chunk) {
console.log('Got ' + chunk.length + ' bytes.');
});
from needle.
Related Issues (20)
- Mangled file content when multipart-POSTing a file with a "text/*" content type HOT 2
- Very infrequent TypeError: iconv.encodingExists is not a function
- Tunnelling doesn't work in v3.1.0 HOT 12
- Proposal: Supporting User-Defined "Follow If" Conditions
- Piping needle request to Express response won't set the correct headers
- Multiple Files Upload Renames Input Field
- Uncaught asynchronous error
- Remote end closed socket abruptly errors HOT 2
- a ':' in nonce breaks digest authentication HOT 1
- Digest MD5 not working with Geovision IP Camera
- Uncaught ECONNRESET exception
- needle.get cannot guaranty getting the http stream HOT 2
- FEATURE: Retry HOT 1
- follow_set_cookies -> not working!!!
- Bug in 3.3.0: accidental creation of `global.signal`, gets caught in strict UTs
- README recommends mikeal's request HOT 3
- Multipart uploads strips date values in the request body HOT 2
- Doesn't work in Cloudflare Workers HOT 1
- Sorry, I was about to post this issue to a different repo, don't even know how it happened that I posted it here
- `get` with redirect leads to ~30sec hang HOT 7
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 needle.