- Drivers support
- Uploading and attach file flow for
local
driver - Uploading and attach file flow for
s3
driver - Uploading and attach file flow for
s3-presigned
driver - How to delete files?
Out-of-box we support the following drivers: local
, s3
, and s3-presigned
. You can set it in the .env
file, variable FILE_DRIVER
. If you want to use another service for storing files, you can extend it.
For production we recommend using the "s3-presigned" driver to offload your server.
Endpoint /api/v1/files/upload
is used for uploading files, which returns File
entity with id
and path
. After receiving File
entity you can attach this to another entity.
sequenceDiagram
participant A as Fronted App
participant B as Backend App
A->>B: Upload file via POST /api/v1/files/upload
B->>A: Receive File entity with "id" and "path" properties
note left of A: Attach File entity to User entity
A->>B: Update user via PATCH /api/v1/auth/me
file-uploading.mp4
Endpoint /api/v1/files/upload
is used for uploading files, which returns File
entity with id
and path
. After receiving File
entity you can attach this to another entity.
-
Click "Create bucket"
-
Create bucket (for example,
your-unique-bucket-name
) -
Open your bucket
-
Click "Permissions" tab
-
Find "Cross-origin resource sharing (CORS)" section
-
Click "Edit"
-
Paste the following configuration
[ { "AllowedHeaders": ["*"], "AllowedMethods": ["GET"], "AllowedOrigins": ["*"], "ExposeHeaders": [] } ]
-
Click "Save changes"
-
Update
.env
file with the following variables:FILE_DRIVER=s3 ACCESS_KEY_ID=YOUR_ACCESS_KEY_ID SECRET_ACCESS_KEY=YOUR_SECRET_ACCESS_KEY AWS_S3_REGION=YOUR_AWS_S3_REGION AWS_DEFAULT_S3_BUCKET=YOUR_AWS_DEFAULT_S3_BUCKET
sequenceDiagram
participant A as Fronted App
participant B as Backend App
participant C as AWS S3
A->>B: Upload file via POST /api/v1/files/upload
B->>C: Upload file to S3
B->>A: Receive File entity with "id" and "path" properties
note left of A: Attach File entity to User entity
A->>B: Update user via PATCH /api/v1/auth/me
Endpoint /api/v1/files/upload
is used for uploading files. In this case /api/v1/files/upload
receives only fileName
property (without binary file), and returns the presigned URL
and File
entity with id
and path
. After receiving the presigned URL
and File
entity you need to upload your file to the presigned URL
and after that attach File
to another entity.
-
Click "Create bucket"
-
Create bucket (for example,
your-unique-bucket-name
) -
Open your bucket
-
Click "Permissions" tab
-
Find "Cross-origin resource sharing (CORS)" section
-
Click "Edit"
-
Paste the following configuration
[ { "AllowedHeaders": ["*"], "AllowedMethods": ["GET", "PUT"], "AllowedOrigins": ["*"], "ExposeHeaders": [] } ]
For production we recommend to use more strict configuration:
[ { "AllowedHeaders": ["*"], "AllowedMethods": ["PUT"], "AllowedOrigins": ["https://your-domain.com"], "ExposeHeaders": [] }, { "AllowedHeaders": ["*"], "AllowedMethods": ["GET"], "AllowedOrigins": ["*"], "ExposeHeaders": [] } ]
-
Click "Save changes"
-
Update
.env
file with the following variables:FILE_DRIVER=s3-presigned ACCESS_KEY_ID=YOUR_ACCESS_KEY_ID SECRET_ACCESS_KEY=YOUR_SECRET_ACCESS_KEY AWS_S3_REGION=YOUR_AWS_S3_REGION AWS_DEFAULT_S3_BUCKET=YOUR_AWS_DEFAULT_S3_BUCKET
sequenceDiagram
participant C as AWS S3
participant A as Fronted App
participant B as Backend App
A->>B: Send file name (not binary file) via POST /api/v1/files/upload
note right of B: Generate presigned URL
B->>A: Receive presigned URL and File entity with "id" and "path" properties
A->>C: Upload file to S3 via presigned URL
note right of A: Attach File entity to User entity
A->>B: Update user via PATCH /api/v1/auth/me
We prefer not to delete files, as this may have negative experience during restoring data. Also for this reason we also use Soft-Delete approach in database. However, if you need to delete files you can create your own handler, cronjob, etc.
Previous: Serialization
Next: Tests