MediaManager is a micro-service written in Vapor, a server-side Swift framework. It works as an interface for media storage APIs such as Amazon S3 and Google Cloud Storage.
Note: MediaManager has Amazon S3 implemented by default. This can be removed if desired.
After forking and cloning the repo, you can configure the various services used for storing resources. MediaManager already has Amazon S3 configured, so you can follow it, but here is an outline of what you need to do:
Install the storage client package for the service you wish to use. A list of available services can be found here.
For cleanness sake, create a new file in the
Sources/App/Configurationdirectory for the service you are using.
Add a function to your new file that will take in an
In the function you create, register the required services used by the storage service. Then add the storage service itself to the cache:
cache.register(storage: Storage.self, slug: "storage")
Note: The slug value will be used to construct a controller's routes.
configuration.swiftfile, add a call to your function, passing in the
let cache = StorageControllerCache() try storage(&services, cache: cache) // <== Add line services.register(cache)
That's it! The storage service is now available through the MediaManager API.
The routes for the MediaManager are all under the
/*/media-manager path. Each service is registered under the slug that it configured with,
/*/media-manager/s3 for example.
Each service has 4 routes:
Stores the new file under the service in the URL.
| Parameter | Description | |------------|----------------------------------------------| |
filename| The relative directory and name for the file | |
data| The contents of the file |
Fetches the contents of a file under the given directory and filename in the URL suffix.
Replaces the contents of a file under the given directory and filename in the URL suffix.
| Parameter | Description | |-----------|-------------------------------| |
data| The new contents of the file |
Deletes the file
The MediaManager service is under the MIT license agreement.
Help us keep the lights on
0.1.0 - Dec 19, 2018
The first release of MediaManager! Be sure to checkout the README.
Handles resource storage for multiple services at a time, such as Amazon S3, Google Cloud Storage, and BackBlaze B2 (coming soon).