rkusa / koa-formidable

Formidable middleware for Koa
MIT License
25 stars 2 forks source link

upload progress? #5

Open smolleyes opened 8 years ago

smolleyes commented 8 years ago

hi

everything is in the title, can t get it working

just doing a simple

var form = yield formidable.parse(this);
console.log(form)
form.on('progress', function(bytesReceived, bytesExpected) {
      console.log(bytesReceived, bytesExpected)
});

TypeError: form.on is not a function

how can we do please?

thanks

rkusa commented 8 years ago

Something like the following could work (untested):

var form = new require('formidable').IncomingForm()
form.on('progress', function(bytesReceived, bytesExpected) {
      console.log(bytesReceived, bytesExpected)
})
var result = yield formidable.parse(form, this)
smolleyes commented 8 years ago

hello

thanks for the reply

the form works but nothing is printed in the console :/

rkusa commented 8 years ago

Did you integrated the form.on('progress', ...) and yield formidable.parse(...) in the same order as in the snippet, so the event registration before blocking because of the yield?

smolleyes commented 8 years ago

my code is

//parse le form
var f = new require('formidable').IncomingForm()
f.on('progress', function(bytesReceived, bytesExpected) {
        console.log(bytesReceived+'/'+bytesExpected)
})
console.log(f)
var form = yield formidable.parse(f, this)

so yes :)

smolleyes commented 8 years ago

hello

this is very strange :

1/ the progress event seems called only once the file is totally uploaded.. 2/ why the hell the file is not viewable while uploading in my uploadDir, i can only see it when the file is totaly uplodded i don t know where it s writed while uploading :/

thanks !

rkusa commented 8 years ago

These issues seem to be more related to formidable itself than to the koa wrapper. Anyway:

1) Maybe you will get more events when trying a bigger file or when uploading not from localhost to localhost? 2) try the term temporary path on https://github.com/felixge/node-formidable

smolleyes commented 8 years ago

hello

i try with files of 300mo to 13 GB ! can t do bigger :) from localhost or to my server same thing

i try to update my formidable package then look at this

you mean the file.path = null ?

normally it seems i need to set this in the fileBegin event but this event do not work for the moment, i retry

brb !

rkusa commented 8 years ago

Yes, I mean the sentence above that

The path this file is being written to. You can modify this in the 'fileBegin' event in case you are unhappy with the way formidable generates a temporary path for your files.

However, I never changed the temporary path myself. So cannot actually help with that, but it is common practice to upload files to a temporary location and just move them to the final location once uploading has finished.

For the progress issue I would recommend to search stackoverflow and formidable's issue page.

smolleyes commented 8 years ago

same problem ....

here s my route, i stop it with a return just after parse now to test...

// post add function
module.exports.add = function *() {
    var socket = io('http://localhost:3000');

    var results = {};
    doc = {};
    docs = [];
    //parse le form
    var f = new formi.IncomingForm();
    f.uploadDir = "/data/websites/traceroute/uploads";

    f.on('fileBegin', function(name, file) {
      console.log(name + ' ' + file + " upload started!")
    });

    f.on('progress', function(bytesReceived, bytesExpected) {
        socket.emit('formMsg', bytesReceived+'/'+bytesExpected)
    })

    console.log(f)
    var form = yield formidable.parse(f, this)

    return;
}

i can t see any log before the file is 100% uploaded

smolleyes commented 8 years ago

as you can see i already use a custom uploadDir and it works but this file is writed there after upload completed not while uploading Oo

rkusa commented 8 years ago

I think there is a difference between the upload dir and the temporary location during upload.

smolleyes commented 8 years ago

https://github.com/felixge/node-formidable/issues/377

smolleyes commented 8 years ago

yes but i think i can t use this since the fileBegin event do not work :/

i ll try ...

rkusa commented 7 years ago

Is maybe fixed with version 1.1.0. Better late than never 😏