GithubHelp home page GithubHelp logo

Comments (8)

fedegratti avatar fedegratti commented on July 19, 2024 3

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.

tomas avatar tomas commented on July 19, 2024

You mean from the command line or through your app?

from needle.

dlion avatar dlion commented on July 19, 2024

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.

tomas avatar tomas commented on July 19, 2024

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.

dlion avatar dlion commented on July 19, 2024

Damn, I saw that: https://github.com/IndigoUnited/node-request-progress but this is for request modules.
Dammit.

from needle.

tomas avatar tomas commented on July 19, 2024

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.

dlion avatar dlion commented on July 19, 2024

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.

tomas avatar tomas commented on July 19, 2024

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)

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.