https://github.com/becodeorg/pijon
⚙️ Pijon, the delivery man - File upload lambda preparator
https://github.com/becodeorg/pijon
internal-tool
Last synced: about 2 months ago
JSON representation
⚙️ Pijon, the delivery man - File upload lambda preparator
- Host: GitHub
- URL: https://github.com/becodeorg/pijon
- Owner: becodeorg
- Created: 2019-07-20T07:47:43.000Z (almost 6 years ago)
- Default Branch: develop
- Last Pushed: 2023-01-23T23:43:04.000Z (about 2 years ago)
- Last Synced: 2025-01-10T12:09:08.819Z (3 months ago)
- Topics: internal-tool
- Language: JavaScript
- Homepage:
- Size: 5.2 MB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 32
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# BeCode: pijon
> ⚙️ Pijon, the delivery man - File upload lambda preparator
* * *
## About
Uploading file from a SPA needs a server to handling file.
But what to do when you are working on a _static_ SPA?**pijon** is a lambda serverless function, preparing requests for uploading files to AWS S3 bucket.
Calling **pijon** with a *file name* and a *mime type*, it will generates two URLs: the first is your *endpoint* to upload the file to your S3 bucket, and the second will be the final public URL of your file when the upload is done.
## Installation
Firstly, run the classic `npm install` to install dependencies.
You will also need to create the file `env/sls.env.json`, following this structure:
```json
{
"dev": {
"SERVICE_XXXXXXXXXXXX_BUCKET": "my-s3-bucket-name",
"SERVICE_XXXXXXXXXXXX_ORIGIN": "www.my-site.me,api.my-site.me"
}
}
```The `XXXXXXXXXXXX` in the keys are your *pijon service id*, that will be used to know to which bucket send files, and verify the origin of the request.
## Usage
Simply call the URL on of the lambda with `POST` request with three properties:
- `service`: your *pijon service id* as explained
- `name`: the name of the file that will be uploaded
- `type`: the *mime type* of the file that will be uploaded
- `acl`: the *ACL* to applied to the upload (defaults to `"public-read"`).The call will respond a `json object` with following properties:
- `bucket`: the name of the bucket on which the file is stored
- `key`: the key of the file on the bucket
- `region`: the region where the bucket is stored
- `uploadUrl`: the URL to make a `PUT` request to with your file
- `objectUrl`: the final, public URL of your file on your S3 bucket, after the upload is done> ⚠️ when you upload your file to the `uploadUrl`, don't forget to add a `Content-Type` header to your request, matching the *mime type* of your file!
### Development
Run `npm run build` to build the code.
#### Deployment
You need to have [setup](https://serverless.com/framework/docs/providers/aws/guide/credentials/) the appropriate user from AWS and stored it in your `~/.aws/credentials`.
##### Dev deployment
npm run deploy:dev --aws-profile=
##### Production deployment
npm run deploy:prod --aws-profile=
* * *
July 2019, leny.