-1

How can I upload/download files in the simplest way using storageService.upload and storageService.download function from my JavaScript/Loopback code? I'm trying do something like that:

app.post("/sendFile", (req, res) => client.upload( req, res, {}, () => {console.log("cb")} ) );

But this doesn't work. I make my REST request with Advanced Rest Client Application in Google Chrome. I set Content-Type for multipart-form-data and add my jpg file in files section.

I got Failed to create a multipart upload on S3: {"message":"Missing required key 'Bucket' in params","stack":"MissingRequiredParameter: Missing required key 'Bucket' in params (...) error.

I'm newbie here, but I have impression that Loopback documentation should be much better. Thanks for help!

pstrag
  • 617
  • 5
  • 16
  • Have you done any research on that error message? It seems rather clear. – Kevin B Mar 18 '16 at 20:12
  • Yeah, I understand the error, but - to be honest - I don't know where to specify this Bucket thing [I've tried to do that in form, in option parameter etc., but it don't work], documentation isn't very helpful. – pstrag Mar 19 '16 at 00:10
  • It would go somewhere in your loopback config files. – Kevin B Mar 19 '16 at 15:01

1 Answers1

0

I got the exact same error, and fixed by adding a property to the req-object with your bucket name, before calling .upload() - like so:

app.post("/sendFile", (req, res) => {
  req.params.container = "name-of-your-bucket";
  client.upload( req, res, {}, (err, fileObject) => {});
});

Or an perhaps even better way if you are going to define some options:

app.post("/sendFile", (req, res) => {

  var options = {
    container: "name-of-your-bucket"
  };

  client.upload( req, res, options, (err, fileObject) => {});
});

To make upload/download work with Loopback I recommend this Stackoverflow question

Community
  • 1
  • 1
Jesper Bruun Hansen
  • 376
  • 2
  • 5
  • 16