https://github.com/pellizzetti/adonis-s3-upload-download-example
Simple example of a file upload/download routine using AdonisJS
https://github.com/pellizzetti/adonis-s3-upload-download-example
Last synced: 9 months ago
JSON representation
Simple example of a file upload/download routine using AdonisJS
- Host: GitHub
- URL: https://github.com/pellizzetti/adonis-s3-upload-download-example
- Owner: pellizzetti
- Created: 2019-03-20T17:33:07.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2022-12-22T10:45:42.000Z (over 3 years ago)
- Last Synced: 2025-01-10T12:15:12.867Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 524 KB
- Stars: 6
- Watchers: 4
- Forks: 1
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# adonis-s3-upload-example
Simple example of a file upload routine using **AdonisJS**
## Getting started
Install dependencies:
```sh
npm install
# OR
# yarn
```
Run the application:
```
adonis serve --dev
```
## Routes
```
GET '/picture/:filename' => 'PictureController.show'
GET '/picture/:filename/download' => 'PictureController.download'
POST '/picture' => 'PictureController.upload'
```
### Methods
> app/Controllers/Http/PictureController.js
---
#### show()
Return if a file exists in bucket and his formatted url.
##### Parameters
| Name | Type | Description |
| --------------- | -------- | ----------------------- |
| params.filename | `string` | Filename to be queried. |
##### Returns
- `{ exists: boolean, fileUrl: string }` Status object
---
#### download()
Get file from bucket and save to local disk.
If file doesn't exist return error message.
##### Parameters
| Name | Type | Description |
| ----------------- | ---------- | --------------------------------------------- |
| params.filename | `string` | Filename to be queried. |
| response.send | `function` | Sets the response body for the HTTP request |
| response.download | `function` | Stream a file to the client as HTTP response. |
##### Returns
- `ResponseStream` Pipe stream to the response
---
#### upload()
Upload file to bucket.
##### Parameters
| Name | Type | Description |
| ------------------------- | ---------- | ---------------------------------------------------- |
| request.multipart.file | `function` | Add a listener to file. |
| request.multipart.process | `function` | Process files by going over each part of the stream. |
##### Returns
- `string` Upload successful message.