1.2.54 • Published 4 years ago

@pubsweet/component-aws-s3 v1.2.54

Weekly downloads
57
License
MIT
Repository
gitlab
Last release
4 years ago

AWS S3 File Upload Configuration

In order to use this component, the following configuration needs to be added to a PubSweet application inside a section named pubsweet-component-aws-s3:

  • secretAccessKey: the AWS_S3_SECRET_KEY value from the app's .env file
  • accessKeyId: the AWS_S3_ACCESS_KEY value from the app's .env file
  • region: the AWS_S3_REGION value from the app's .env file
  • bucket: the AWS_S3_BUCKET value from the app's .env file

For example:

"pubsweet-component-aws-s3": {
    "secretAccessKey": "process.env.AWS_S3_SECRET_KEY",
    "accessKeyId": "process.env.AWS_S3_ACCESS_KEY",
    "region": "process.env.AWS_S3_REGION",
    "bucket": "process.env.AWS_S3_BUCKET",
    "validations": "path.resolve(__dirname, 'upload-validations.js')",
  },

The .env file should look like this:

AWS_S3_ACCESS_KEY = exampleKey
AWS_S3_SECRET_KEY = exampleKey/sads/21
AWS_S3_REGION = region-name
AWS_S3_BUCKET = bucket-name

Then, as soon as possible in your app you should add the dotenv package:

require('dotenv').config()

component-aws-s3 API

A list of endpoints that help you upload, download and delete S3 files.

Upload a file POST

Request

POST /api/file

Request body

Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryWfPNVh4wuWBlyEyQ

------WebKitFormBoundaryWfPNVh4wuWBlyEyQ
Content-Disposition: form-data; name="fileType"

supplementary
------WebKitFormBoundaryWfPNVh4wuWBlyEyQ
Content-Disposition: form-data; name="fragmentId"

545
------WebKitFormBoundaryWfPNVh4wuWBlyEyQ
Content-Disposition: form-data; name="file"; filename="attachment.txt"
Content-Type: text/plain

[file content goes there]
------WebKitFormBoundaryWfPNVh4wuWBlyEyQ

Response

{
  "id": "fragment-id/file-id",
  "name": "Document Name.doc",
  "size": 452097
}

Retrieve file signed URL GET

This endpoint allows you to retrieve a file's signed URL that can be used to download the file.

Request

GET /api/files/{fragmentId}/{fileId}

URI ParameterRequieredRequirementsDescription
fragmentIdYesStringThe ID of the fragment
fileIdYesStringThe ID of the file
Query ParameterRequieredRequirementsDescription
downloadNoBooleanGet the file data blob if set to true.

Response

HTTP/1.1 200
{
	"signedUrl": "aws-url"
}

Retrieve files as zip GET

This endpoint allows you to retrieve a fragment's files as a zip archive.

Request

GET /api/files/{fragmentId}

URI ParameterRequieredRequirementsDescription
fragmentIdYesStringThe ID of the fragment
Query ParameterRequieredRequirementsDescription
fileTypesNoArray(String)Specify which file types to be included in the zip. All file types will be included if omitted

Response

HTTP/1.1 200
{
	"dataBlob"
}

Delete file DELETE

Request

DELETE /api/file/{fileId}

URI ParameterRequieredRequirementsDescription
fileIdYesStringThe ID of the file

Response

HTTP/1.1 204

1.2.53

4 years ago

1.2.54

4 years ago

1.2.52

4 years ago

1.2.51

4 years ago

1.2.50

4 years ago

1.2.49

4 years ago

1.2.48

4 years ago

1.2.47

4 years ago

1.2.46

4 years ago

1.2.45

4 years ago

1.2.44

4 years ago

1.2.43

4 years ago

1.2.42

5 years ago

1.2.41

5 years ago

1.2.40

5 years ago

1.2.39

5 years ago

1.2.38

5 years ago

1.2.37

5 years ago

1.2.36

5 years ago

1.2.35

5 years ago

1.2.34

5 years ago

1.2.33

5 years ago

1.2.32

5 years ago

1.2.31

5 years ago

1.2.30

5 years ago

1.2.29

6 years ago

1.2.28

6 years ago

1.2.27

6 years ago

1.2.26

6 years ago

1.2.25

6 years ago

1.2.24

6 years ago

1.2.23

6 years ago

1.2.22

6 years ago

1.2.21

6 years ago

1.2.20

6 years ago

1.2.19

6 years ago

1.2.18

6 years ago

1.2.17

6 years ago

1.2.16

6 years ago

1.2.15

6 years ago

1.2.14

6 years ago

1.2.13

6 years ago

1.2.12

6 years ago

1.2.11

6 years ago

1.2.10

6 years ago

1.2.9

6 years ago

1.2.8

6 years ago

1.2.7

6 years ago

1.2.6

6 years ago

1.2.5

6 years ago

1.2.4

6 years ago

1.2.3

6 years ago

1.2.2

7 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago