local
driver
s3
driver
s3-presigned
driver
Out-of-box boilerplate supports 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.
local
driverEndpoint /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
https://user-images.githubusercontent.com/6001723/224558636-d22480e4-f70a-4789-b6fc-6ea343685dc7.mp4
s3
driverEndpoint /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.
s3
driveryour-unique-bucket-name
)Paste the following configuration
[
{
"AllowedHeaders": ["*"],
"AllowedMethods": ["GET"],
"AllowedOrigins": ["*"],
"ExposeHeaders": []
}
]
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
s3-presigned
driverEndpoint /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.
s3-presigned
driveryour-unique-bucket-name
)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": []
}
]
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