balderdashy / sails

Realtime MVC Framework for Node.js
https://sailsjs.com
MIT License
22.85k stars 1.95k forks source link

Skipper:Skipper ignores upstreams whose param names end in "[]" #4702

Open vinhtq opened 9 years ago

vinhtq commented 9 years ago

When i try to upload one file, everything is ok! But when i upload multiples, skipper does not work! I think because the upload try to use array in their param, so skipper does not understand!

Here is the code: HTML:

<form enctype="multipart/form-data" action="post_upload.php" method="POST">
<input type="file" name="file[]" multiple />
<input type="submit" name="upload" value="Upload" />
</form>

Sailsjs:

req.file('files').upload(function (err, uploadFiles) {
console.log(uploadFiles.length);
});

The log always give the 0 result

RSSGergelyMunkacsy commented 9 years ago

I think you need to use file key instead of filesin Sailjs.

vinhtq commented 9 years ago

Sorry for this mistake! But i still cannot upload if i change the name to file instead of files Could you please take a look at this issues: https://github.com/balderdashy/skipper/issues/63

RSSGergelyMunkacsy commented 9 years ago

Sorry, I have no time for digging into it correctly, but for me, this is work correctly:

[Create.hbs]
<input class="form-control uniform_on" id="uploadImages" name="image" type="file" multiple>
[SomeController.js]
req.file('image').upload({dirname: uploadDir}, function onUploadComplete(err, uploadedImages) {
      if (!!err) {
        return callback(err, null);
      }

So I don't use [] in the input name, the skipper handle it for me and in the uploadedImages I get an array of images.

vinhtq commented 9 years ago

Thank you for you response! But you cannot force people to do that because it works on php if you use [] in the input! My problem is the same, i use dropzonejs. Dropzonejs automatically add [] to the input name when i upload multiple files!

<form action="file-upload.php" method="post" enctype="multipart/form-data" multiple>
  <input name="userfile[]" type="file" /><br />
  <input type="submit" value="Send files" />
</form>

Above code works in php, so why not sailsjs?

I think skipper should fix this bug!

sailsbot commented 9 years ago

Thanks for posting, @vinhtq. I'm a repo bot-- nice to meet you!

It has been 60 days since there have been any updates or new comments on this page. If this issue has been resolved, feel free to disregard the rest of this message. On the other hand, if you are still waiting on a patch, please:

Thanks so much for your help!

mrcarl79 commented 8 years ago

This is a problem for me also as ng-file-upload passes the files as an array like this, but it gets ignored in skipper/sailsjs. Any thoughts?

------WebKitFormBoundaryWCbq6JPGGudQoBmR Content-Disposition: form-data; name="file[0]"; filename="full_13246-w1000h0.jpg" Content-Type: image/jpeg

------WebKitFormBoundaryWCbq6JPGGudQoBmR Content-Disposition: form-data; name="file[1]"; filename="full_13284-w1000h0.jpg" Content-Type: image/jpeg

mrcarl79 commented 8 years ago

Just done a typical spend hours trying to fix something then 5 minutes after posting about it I fix it lol

If anyone has my same issue put an arrayKey: '' property in the ng-file-upload config like this:

Upload.upload({ url: 'http://localhost/upload', arrayKey: '', data: { file: files } });

Then it works ok with sailsjs :)

ram-you commented 8 years ago

@mrcarl79 Thank you very very much. You and the arrayKey: '' saved my life.

mikermcneil commented 7 years ago

@mrcarl79 thanks for posting that!

@vinhtq @RSSGergelyMunkacsy @ram-you @mrcarl79 Would love to merge a patch for this, but in the mean time I'm going to reopen this issue and change the title to clarify that this is an issue related to field name, so we have this tracked. See https://twitter.com/mikermcneil/status/806286981856710656 and https://gitter.im/balderdashy/sails?at=58475141bc32453c289d5e9a for reference.

mukk85 commented 7 years ago

Any progress on this issue?

gopalkohli commented 7 years ago

@mrcarl79 +1

raqem commented 5 years ago

Hi @vinhtq, @RSSGergelyMunkacsy, @mrcarl79, @ram-you Just letting everyone know we are consolidating all the open Sails issues into one repo. ~Cheers!

johnabrams7 commented 5 years ago

@vinhtq @RSSGergelyMunkacsy @mrcarl79 @mukk85 @ram-you @forestallers - Sails v1.1.0 has many updates for skipper. There's also a skipper edge version 0.9.0-4 that was released 3 months ago for further testing. Has anyone tested this out with the latest Sails v1.1.0?