Comments (11)
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.
@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.
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.
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.
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.
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.
what i write wrong, can u help @alexindigo ?
from form-data.
Let me play with it to come up with working example. I'll get back to you soon.
from form-data.
@alexindigo thx!
from form-data.
@alexindigo how are you doing ?
from form-data.
@miukki Hey, sorry holidays took the best of me :) Getting back on track.
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 2
- "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.