Files

File Storage Service, or simply File Service, extends the DreamFactory REST API with a generic interface to use
local (DreamFactory server) and/or remote storage (Amazon S3, Azure blob, Rackspace, etc.) services seamlessly
without having to worry about the differences among them.

File Services are native services of DreamFactory
and are supported by features like role-service-access, lookup usage, live API documentation, and caching. Once your file
service is configured in DreamFactory, all the configuration details like service credentials are hidden from your client.
They are securely stored on your DreamFactory instance database. This allows for a simple, secure, and consistent way to
access your local and remote storage services via the DreamFactory REST API.

There are primarily two types of File Services: Local and Remote/Cloud.

Note: As of DreamFactory 2.3.1, all files downloaded using the file services are downloaded in chunks in order to support large files. The default chunk size is 10MB. You can change the chunk size by changing (and uncommenting) the environment flag DF_FILE_CHUNK_SIZE in the .env file.

Contents

Local File Service

The Local File Service comes pre-configured in a fresh installation and by default allows you to use the server disk storage where your
DreamFactory instance is hosted. The default root of this local file storage is /your-dreamfactory-installation-root/storage/app/.
You can change this default root simply by uncommenting and changing the DF_LOCAL_FILE_ROOT setting in the .env file located in your
DreamFactory installation root.

You can also configure the Local File Service for your DreamFactory instance to use cloud storage or even network storage mounted on your server. Please see the container section in the service configuration below for details.

Remote/Cloud File Service

DreamFactory also supports cloud-based storage services using the same REST API that's used for the Local File Service. The following
cloud storage services are currently supported.

Configuration

File services are managed via the api/v2/system/service API endpoint under the system service and have the following service types.

Service Type

Storage Service

Configurations

local_file

Local File Storage

{//Choose a URL safe service name"name":"files",//Choose a label for your service"label":"Local File Storage",//A short description of your service"description":"Service for accessing local file storage.",//Boolean flag to activate/inactivate your service"is_active":true,//Service type"type":"local_file","config":{"public_path":["public/folder1/","public/folder2/"],//A folder path from your system root, or a path relative to the configured //storage folder for this installation, i.e. /home/vagrant/code/storage. //This path must be readable and writable by the web server."container":"local"}}

{//Choose a URL safe service name"name":"gridfs",//Choose a label for your service"label":"gridfs",//A short description of your service"description":"A GridFS storage service",//Boolean flag to activate/inactivate your service"is_active":true,//Service type"type":"gridfs","config":{"host":"x.x.x.x","port":"27017","database":"gridfs","username":"gridfsuser","password":"**********","dsn":"null or dsn string if not using above connection parameters","options":[],"driver_options":[],"public_path":["public/folder1/","public/folder2/"]}}

Notice that all storage type configurations ("config" section) have public_path and container configuration in common. The cloud storage types have some extra self-explanatory configuration
items that are specific to the corresponding cloud vendors.

The following describes the two common configurations across all storage service types:

public_path

Array of texts. Optional. If you want to make any of your storage directories public (accessible from anywhere), then
you can list those directories under public_path config. Once you make your directories public, you can
access them via the API http://your-instance/<service>/<path>/<file>. For example, let's say you create
a Local File Service using the following config.

container

Text. Required. For remote/cloud storage service types, this is the name of your bucket/root directory. However, for
Local File Storage, this is a full folder path from your system root, or a path relative to the configured storage folder for this installation, i.e. /home/vagrant/code/storage. This path must be readable and writable by the web server.

Below is how the default disks configuration looks. You can choose any of these disks (local, s3, rackspace, azure) as your container for
your Local File Storage. The default is 'local'.

If you choose any of the cloud-based storage options, make sure that the corresponding service credentials are in the .env file. For example, if you choose 's3' as your container, then you'll need to define the
following options in the .env file.

AWS_S3_KEY
AWS_S3_SECRET
AWS_S3_REGION
AWS_S3_CONTAINER

You can also define your own disk and add it to this list. For example, if you want to use network storage mounted on your
server as the storage for your Local File Service, then define your 'network_mount' disk and add it to the list like below.
Once your disk is added to this list, you can use it for your Local File Service container.