Gravity
Search…
File Uploads
You can upload files via the React form using an input prop of file. The file component supports multiple file uploads using a drag & drop interface.
Uploads are handled on the server using multer and stored in the /uploads directory.
There is a utility API endpoint you can use for uploading files.
1
/api/utility/upload
Copied!
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.
1
const multer = require('multer');
2
const upload = multer({ dest: 'uploads' });
3
api.post('/api/utility/upload', upload.any(), use(utilityController.upload));
Copied!

Uploading Files to Amazon S3

Gravity includes a model for interacting with S3, so you can manage your S3 buckets and files in a few lines of code.
1
// list the buckets
2
await s3.bucket();
3
4
// list the items in the bucket
5
await s3.bucket.items(bucketName);
6
7
// create a new bucket
8
await s3.bucket.create(bucketName);
9
10
// delete a bucket
11
await s3.bucket.delete(bucketName);
12
13
// upload a file
14
await s3.upload(bucketName, file);
15
16
// delete a file
17
await s3.delete(bucketName, file);
18
19
// get a signed url for a file
20
await s3.signedURL(bucketName, fileName, expires);
Copied!
Last modified 7mo ago