@amplication/plugin-storage-core

0.0.2 • Public • Published

@amplication/plugin-storage-core

NPM Downloads

Purpose

This plugin is used for integrating storage services into your app generated by Amplication. The plugin will add the required core functionality on top of which other storage services can be built.

[!CAUTION] The other storage plugins should have plugin ids of the form storage-<provider> and should be added through the plugins page of the app settings before adding this plugin to get the expected functionality.

Working with the plugin

It can be used by adding the plugin in the plugins page of the app settings. For this plugin, no additional settings are required.

[!NOTE] There should be enitities with fields of data type File for this plugin to generate any additional functionality.

What the plugin does

Adds resolver and controller methods

The following methods are added for each field of type File in the entities:

Resolver methods:

  • upload< FieldName in PascalCase >: Upload a file to the storage service.
  • delete< FieldName in PascalCase >: Delete the file from the storage service.

Controller methods:

  • upload< FieldName in PascalCase >: Upload a file to the storage service.
  • delete< FieldName in PascalCase >: Delete the file from the storage service.
  • download< FieldName in PascalCase >: Download the file from the storage service.

Generates the configuration for file upload services

It adds graphqlUploadExpress middleware to the express app to let the app handle file uploads.

Adds the storage core service abstract class

The plugin adds the StorageService abstract class which can be extended to create storage services for different storage providers. The class does the following:

  • Checks if the file is of the correct mimetype and size.
  • Generates a unique file name.
  • Gives proper mime type while downloading the file.

How is file upload handled?

When a file is uploaded, the file is saved through the storage service and the following JSON is saved in the database:

{
  "uuid": "/path/to/file", // UUID for the file (can be used to retrieve the file eg. URL or file path)
  "filename": "profilePicture-<id of entity>",
  "mimetype": "image/jpeg",
  "encoding": "7bit",
  "size": 123456, // File size in bytes
  "metadata": {} // Provider specific metadata
}

Scripts

build

Running npm run build will bundle your plugin with Webpack for production.

dev

Running npm run dev will watch your plugin's source code and automatically bundle it with every change.

Readme

Keywords

none

Package Sidebar

Install

npm i @amplication/plugin-storage-core

Weekly Downloads

5,276

Version

0.0.2

License

Apache-2.0

Unpacked Size

3.12 MB

Total Files

41

Last publish

Collaborators

  • amplication-bot
  • mulygottlieb
  • levivannoort
  • overbit
  • morhag
  • amitbarletz
  • yuvalhazaz