1

I'm doing multipart file upload with Loopback and I'm using http://loopback.io/doc/en/lb2/Storage-component.html for handling file uploads.

Now I want to add fields in form. How do I get those parameters to loopback?

<form action="http://localhost:3000/api/example/upload" method="post" enctype="multipart/form-data">
    <label for="text">Text:</label>
    <input type="text" name="text" id="text" />
    <label for="file">Filename:</label>
    <input type="file" name="file" id="file" />
    <input type="submit" name="submit" value="Submit" />
</form>

Backend in loopback:

 Example.remoteMethod(
            'upload', {
                http: { path: '/upload', verb: 'post' },
                accepts: [
                    { arg: 'file', type: 'object', http: { source:'body' }},
                    { arg: 'text', type: 'string', http: { source:'body' } },
                    { arg: 'req', type: 'object', http: { source: 'req' } },
                    { arg: 'res', type: 'object', http: { source: 'res' } }
                ],
                returns: { type: 'object', root: true }
            }
        );
user257980
  • 1,059
  • 2
  • 15
  • 31
  • You are possibly having problems with the request headers: http://stackoverflow.com/questions/26723467/what-is-the-difference-between-form-data-x-www-form-urlencoded-and-raw-in-the-p#26730839 – Njuguna Mureithi Mar 30 '17 at 12:25

0 Answers0