npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@amplication/plugin-storage-core

v0.0.2

Published

Adds the core functionality for file upload to Amplication

Downloads

1,285

Readme

@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.