Git Product home page Git Product logo

Comments (11)

miukki avatar miukki commented on July 20, 2024 1

i try to listen for uploading data events via request.post interface (npm request) but it doest work. example code

var form = new FormData();
var uploadFile = fs.createReadStream($scope.data.pathFile);
var r = request.post({uri: url, jar: false, headers: {'X-To-Access-Token': token}}, function (error, response, body){
// response when uploading is done
})

form = r.form();
form.append('file', uploadFile);
form.getLength(function(err, len) {
r.setHeader('Content-Length', len);
});

r.on('data', function (data) {
// have nothing here
})

uploadFile.on('data', function (chunk) {
//its event for read data, not for uploading
})

what i did wrong?

from form-data.

alexindigo avatar alexindigo commented on July 20, 2024 1

@miukki It took me some time to understand what you were trying to do. I hope I got it right. :)
Here is example of progress tracker when FormData used with Request: https://github.com/felixge/node-form-data/pull/56/files#diff-3b8080b944f5c64eb2514fe942b7c60fR60

Let me know if it works for you.

from form-data.

alexindigo avatar alexindigo commented on July 20, 2024

There is no progress event yet (it might be added with new readable streams, nobody knows for sure yet),
as for now form itself is a stream, so you can listen for data events and get uploading chunks.

Let me know if you have more questions.

from form-data.

fengmk2 avatar fengmk2 commented on July 20, 2024

I see. Thanks for your help.

Sent from my iPhone

On 2012-10-4, at 12:19, Alex Indigo [email protected] wrote:

There is no progress event yet (it might be added with new readable
streams, nobody knows for sure yet),
as for now form itself is a stream, so you can listen for data events and
get uploading chunks.

Let me know if you have more questions.


Reply to this email directly or view it on
GitHubhttps://github.com//issues/16#issuecomment-9130196.

from form-data.

alexindigo avatar alexindigo commented on July 20, 2024

Seems like your question is about https://github.com/mikeal/request, but if you can tell us more details on what you're trying to do and what is your environment (node version and whatnot) it might help.

from form-data.

miukki avatar miukki commented on July 20, 2024

can't listen for data events , need get uploading chunks for progress bar . yes im using https://github.com/mikeal/request and i try to listen event

         r.on('data', function (chunk) {
           data.chunk += chunk.length; // so i need data.chunk for progress-bar-uploader  
           console.log(data.chunk);
         })

node version
// process.version
"v0.10.18"

//form-data version
"version": "0.1.2"

//request npm version
"version": "2.27.0"

all part of code

       var form = new FormData();
       var uploadFile = fs.createReadStream($scope.data.pathFile);

       $scope.data.chunk = 0;
       $scope.data.sizeFile = fs.statSync($scope.data.pathFile).size;

       var r = request.post({uri: $scope.data.content_upload_url, jar: false, headers: {'X-To-Access-Token': $token}}, function (error, response, body) {
           console.log('upload done'); //its work/ but i need listen event-uploading
           $scope.ui.loading = false;

           if ((response && response.statusCode == 200) || (response && response.statusCode == 201)) {
               addLog('success upload file');
           } else {
               addLog({type: 'error', data: 'error upload file'}, true);
           };

           apply();
       });

       form = r.form();
       form.append('file', uploadFile);  
       form.getLength(function(err, len) {
           r.setHeader('Content-Length', len);
       });

       //events ReadStream
       uploadFile.on('error', function () {
          addLog({type: 'error', data: ('Error to read file! ' +  $scope.data.pathFile)}, true); 
       });

       uploadFile.on('open', function () {
          addLog('Reading file ' +  $scope.data.pathFile); 
          $scope.ui.progress = true;
          $scope.ui.progressText = 'Reading file: ';
          apply();
       });

       uploadFile.on('data', function (chunk) {
           $scope.data.chunk += chunk.length;apply();
       });

       //event Response
       /* this code didnt get me data.chunk.length
       r.on("response", function (res) {

         var seen = 0
         r.on('data', function (chunk) {
           seen += chunk.length;
           console.log('seen', seen);
         })

       });
       */

from form-data.

miukki avatar miukki commented on July 20, 2024

what i write wrong, can u help @alexindigo ?

from form-data.

alexindigo avatar alexindigo commented on July 20, 2024

Let me play with it to come up with working example. I'll get back to you soon.

from form-data.

miukki avatar miukki commented on July 20, 2024

@alexindigo thx!

from form-data.

miukki avatar miukki commented on July 20, 2024

@alexindigo how are you doing ?

from form-data.

alexindigo avatar alexindigo commented on July 20, 2024

@miukki Hey, sorry holidays took the best of me :) Getting back on track.

from form-data.

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.