Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loopback: How to submit a multipart/form-data upload in loopback-component-storage

loopback-component-storage doc for file (or files) upload says this: loopback documentation

Description:

Upload one or more files into the specified container. The request body must use multipart/form-data which the file input type for HTML uses.

Method:

upload(req, res, cb)

REST URI:

POST
/api/containers/:container/upload

Would someone please show an example of how to create this multipart/form request in Angular/Javascript?

like image 309
zi88 Avatar asked May 23 '16 04:05

zi88


People also ask

How do I upload a multipart form data?

Follow this rules when creating a multipart form: Specify enctype="multipart/form-data" attribute on a form tag. Add a name attribute to a single input type="file" tag. DO NOT add a name attribute to any other input, select or textarea tags.

What is LoopBack storage?

Overview. The LoopBack storage component makes it easy to upload and download files to cloud storage providers and the local (server) file system. It has Node. js and REST APIs for managing binary content in cloud providers, including: Amazon.

How does multipart file upload work?

Multipart upload allows you to upload a single object as a set of parts. Each part is a contiguous portion of the object's data. You can upload these object parts independently and in any order. If transmission of any part fails, you can retransmit that part without affecting other parts.

Why do we use LoopBack files?

So, one of the things that LoopBack makes incredibly easy is handling data in a persistence system. You define a model, let's say Cat, various properties and types, and then LoopBack can handle persisting that in a variety of different storage mechanisms, from Oracle to MySQL to MongoDB.


1 Answers

You can go through code in Loopback Storage example git repository. It internally uses angular-file-upload library which would be beneficial in the future to add filtering on the type, size and number of files.

This example doesn't use lb-services but uses direct calls using $http module.

You'll be able to upload files using the example code. Please let me know in case you need to know angular-file-upload filters to filter out files based on size, type or number of files.

like image 75
Ritesh Jagga Avatar answered Oct 16 '22 09:10

Ritesh Jagga