Skip to content

Latest commit

 

History

History
211 lines (150 loc) · 3.4 KB

File metadata and controls

211 lines (150 loc) · 3.4 KB

loopback-component-storage-gridfs

Uses mongoDB GridFS to manage binary contents of your loopback application.

Inspired by

Behaviors

  • Files are identified by id, not by file name. So it is possible to have files of the same name in one container.

Installation

npm install --save loopback-component-storage-gridfs

Datasource

Add datasource to your datasources.json

"storage": {
   "name": "gridfs",
   "connector": "loopback-component-storage-gridfs",
   "host": "hostname",
   "port": 27017,
   "database": "database",
   "username": "username",
   "password": "password"
 }

username and password are optional

API

List containers

GET /FileContainers
FileContainer.getContainers();

Delete container

DELETE /FileContainers/:containerName
FileContainer.deleteContainer({
  containerName: 'containerName',
  fileId: 'fileId'
});
  • containerName - name of container to delete

List files in container

GET /FileContainers/:containerName/files
FileContainer.getFiles({
  containerName: 'containerName'
});
  • containerName - name of container

Errors:

  • 404 File not found.

Get file information

GET /FileContainers/:containerName/files/:fileId
FileContainer.getFile({
  containerName: 'containerName',
  fileId: 'fileId'
});
  • containerName - name of container
  • fileId - id of file

Get file information by name

GET /FileContainers/:containerName/getFileByName/:filename
FileContainer.getFileByName({
  containerName: 'containerName',
  filename: 'filename'
});
  • containerName - name of container
  • filename - name of file

Delete file

DELETE /FileContainers/:containerName/files/:fileId
FileContainer.deleteFile({
  containerName: 'containerName',
  fileId: 'fileId'
});
  • containerName - name of container
  • fileId - id of file to delete

Delete file by filename

DELETE /FileContainers/:containerName/deleteFileByName/:filename
FileContainer.deleteFileByName({
  containerName: 'containerName',
  filename: 'filename'
});
  • containerName - name of container
  • filename - name of file to delete

Upload files

POST /FileContainers/:containerName/upload
  • containerName - name of container

Download file

GET /FileContainers/:containerName/download/:fileId
  • containerName - name of container
  • fileId - id of file to download

Errors:

  • 404 File not found.

Download container as zip file

GET /FileContainers/:containerName/zip
  • containerName - name of container

Errors:

  • 404 No files to archive.

Download file inline

GET /FileContainers/:containerName/downloadInline/:fileId
  • containerName - name of container
  • fileId - id of file to download in line

Errors:

  • 404 File not found.

Download file inline by name

GET /FileContainers/:containerName/downloadInlineByName/:filename
  • containerName - name of container
  • filename - name of file to download in line

Errors:

  • 404 File not found.