Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http uploads #107

Closed
icedevil opened this issue Feb 13, 2013 · 3 comments
Closed

http uploads #107

icedevil opened this issue Feb 13, 2013 · 3 comments

Comments

@icedevil
Copy link

Hello,

I tried to make a multiple file upload and i got :

api.webServer.fillParamsFromWebRequest = function (connection, varsHash) {
    // -- multiple file upload from formidable
    if (varsHash instanceof Array) {

        connection.params[api.actions.actions[connection.params.action].inputs.multiple] = varsHash;
    } else {
        api.params.postVariables.forEach(function (postVar) {
            if (varsHash[postVar] !== undefined && varsHash[postVar] != null) {
                connection.params[postVar] = varsHash[postVar];
            }
        });
    }
}

this works only with 1 defined multiple upload field :) i know is not an elegant solution, but someone may have the same problem like me

@evantahler
Copy link
Member

Thanks for looking into this!

I've created a test posting both "normal" string params and multiple files and everything seems to be working out for me (OSX, Crome). Would you mind taking a look at this test action and HTML and letting me know where your code differs? Also, I'll add some more detail to the wiki about uploads, seeing as there is none :D

You have also made me realize that I'm not allowing anyone to modify the formidable options! https://github.com/felixge/node-formidable Changing the upload location and max file-size is pretty important. This commit fixes that up evantahler@18080f1


uploader.js (action)

exports.action = {
  name: 'uploader',
  description: 'uploader',
  inputs: {
    required: [], optional: ['file1', 'file2', 'key1', 'key2']
  }, 
  outputExample: null,
  run: function(api, connection, next){
    console.log("\r\n\r\n")
    console.log(connection.params);
    console.log("\r\n\r\n")
    next(connection, true);
  }
};

uploader.html (public)

<html>
    <head></head>
    <body>
        <form method="post" enctype="multipart/form-data" action="http://localhost:8080/api/uploader">
            <input type="file" name="file1" />
            <input type="file" name="file2" />
            <br><br>
            <input type='text' name="key1" />
            <input type='text' name="key2" />
            <br><br>
            <input type="submit" value="send" />
        </form>
    </body>
</html>

example output

2013-02-13 20:32:47 - notice: server ID: 10.0.1.39:8080
2013-02-13 20:32:47 - notice: *** Server Started @ 2013-02-13 20:32:47 ***



{ action: 'uploader',
  file1: 
   { domain: null,
     _events: null,
     _maxListeners: 10,
     size: 5477608,
     path: '/Users/evantahler/PROJECTS/actionHero/tmp/86b2aa018a9785e20b3f6cea95babcca',
     name: '1-02 Concentration Enhancing Menu Initialiser.mp3',
     type: 'audio/mp3',
     hash: false,
     lastModifiedDate: Wed Feb 13 2013 20:32:49 GMT-0800 (PST),
     _writeStream: 
      { ... },
     length: [Getter],
     filename: [Getter],
     mime: [Getter] },
  file2: 
   { domain: null,
     _events: null,
     _maxListeners: 10,
     size: 10439802,
     path: '/Users/evantahler/PROJECTS/actionHero/tmp/6052010f1d75ceaeb9197a9a759124dc',
     name: '1-10 There She Is.mp3',
     type: 'audio/mp3',
     hash: false,
     lastModifiedDate: Wed Feb 13 2013 20:32:49 GMT-0800 (PST),
     _writeStream: 
      { ... },
  key1: '123',
  key2: '456',
  limit: 100,
  offset: 0 }

@evantahler
Copy link
Member

I suddenly realized that you meant a litteral multiple="multiple" in the form! Sorry about that.

Do you happen to know why the main branch of formidable doesn't have @dvv's patch you referenced? It's quite old at this point. However, I also only see 1 of my n files uploaded via this method. I don't want to require a non-NPM'd module in actionHero, and I would also prefer not to need to patch a dependency either.

We are using the current version of formidable...

@evantahler
Copy link
Member

And... it seems like it is still an open issue :/ node-formidable/formidable#33, and has been for some time.

I'm going to close this issue here (as this seems to be philosophical war going on with the formidable community) and call this a won't fix: dependency issue for actionHero.

I'll be sure to update actionHero's dependancies as soon as that issue gets updated, and you guide above is great for anyone who feels gutsy and wants to hack on these modules manually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants