Coder Social home page Coder Social logo

upload progress? about koa-formidable HOT 14 OPEN

rkusa avatar rkusa commented on July 18, 2024
upload progress?

from koa-formidable.

Comments (14)

rkusa avatar rkusa commented on July 18, 2024

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)

from koa-formidable.

smolleyes avatar smolleyes commented on July 18, 2024

hello

thanks for the reply

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

from koa-formidable.

rkusa avatar rkusa commented on July 18, 2024

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?

from koa-formidable.

smolleyes avatar smolleyes commented on July 18, 2024

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 :)

from koa-formidable.

smolleyes avatar smolleyes commented on July 18, 2024

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 !

from koa-formidable.

rkusa avatar rkusa commented on July 18, 2024

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

from koa-formidable.

smolleyes avatar smolleyes commented on July 18, 2024

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 !

from koa-formidable.

rkusa avatar rkusa commented on July 18, 2024

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.

from koa-formidable.

smolleyes avatar smolleyes commented on July 18, 2024

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

from koa-formidable.

smolleyes avatar smolleyes commented on July 18, 2024

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

from koa-formidable.

rkusa avatar rkusa commented on July 18, 2024

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

from koa-formidable.

smolleyes avatar smolleyes commented on July 18, 2024

node-formidable/formidable#377

from koa-formidable.

smolleyes avatar smolleyes commented on July 18, 2024

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

i ll try ...

from koa-formidable.

rkusa avatar rkusa commented on July 18, 2024

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

from koa-formidable.

Related Issues (6)

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.