File Uploads
You can upload files via the React form using input type of file. The file component supports multiple file uploads using a drag-and-drop interface.
<Form inputs={{
avatar: {
label: 'Profile Picture',
type: 'file',
required: false,
max: 1,
},
}}/>Uploads are handled on the server using multer and stored in the /uploads directory.
There is a utility API endpoint for uploading files.
/api/utility/uploadWhen using this endpoint, a temp file will be stored in the /uploads folder by multer. The controller will then upload this file to S3 to your default bucket.
Alternatively, if you want to upload a file to another endpoint, you'll need to use the multer middleware in the same manner as the utility endpoint.
const multer = require('multer');
const upload = multer({ dest: 'uploads' });
api.post('/api/utility/upload', upload.any(), use(utilityController.upload));Uploading Files to Amazon S3
Gravity includes a helper for interacting with S3, so you can manage your S3 buckets and files in a few lines of code.
1. Add AWS Credentials to .env
You need to add the following three credentials to your environment to use the S3 helper:
2. Import The Helper
Import the helper anywhere in your project and call one of the helper methods.
Last updated
Was this helpful?