1.2.54 • Published 3 years ago

@pubsweet/component-aws-s3 v1.2.54

Weekly downloads
57
License
MIT
Repository
gitlab
Last release
3 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

3 years ago

1.2.54

3 years ago

1.2.52

3 years ago

1.2.51

3 years ago

1.2.50

3 years ago

1.2.49

3 years ago

1.2.48

3 years ago

1.2.47

3 years ago

1.2.46

3 years ago

1.2.45

3 years ago

1.2.44

3 years ago

1.2.43

3 years ago

1.2.42

3 years ago

1.2.41

3 years ago

1.2.40

3 years ago

1.2.39

4 years ago

1.2.38

4 years ago

1.2.37

4 years ago

1.2.36

4 years ago

1.2.35

4 years ago

1.2.34

4 years ago

1.2.33

4 years ago

1.2.32

4 years ago

1.2.31

4 years ago

1.2.30

4 years ago

1.2.29

4 years ago

1.2.28

4 years ago

1.2.27

5 years ago

1.2.26

5 years ago

1.2.25

5 years ago

1.2.24

5 years ago

1.2.23

5 years ago

1.2.22

5 years ago

1.2.21

5 years ago

1.2.20

5 years ago

1.2.19

5 years ago

1.2.18

5 years ago

1.2.17

5 years ago

1.2.16

5 years ago

1.2.15

5 years ago

1.2.14

5 years ago

1.2.13

5 years ago

1.2.12

5 years ago

1.2.11

5 years ago

1.2.10

5 years ago

1.2.9

5 years ago

1.2.8

5 years ago

1.2.7

5 years ago

1.2.6

5 years ago

1.2.5

5 years ago

1.2.4

5 years ago

1.2.3

5 years ago

1.2.2

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago