Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow s3 urls to be set as path instead of subdomain + automatic region URL #44

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/RNS3.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import { Request } from './Request'
import { S3Policy } from './S3Policy'

const AWS_DEFAULT_S3_HOST = 's3.amazonaws.com'

const EXPECTED_RESPONSE_KEY_VALUE_RE = {
key: /<Key>(.*)<\/Key>/,
etag: /<ETag>"?([^"]*)"?<\/ETag>/,
Expand All @@ -30,6 +28,14 @@ const setBodyAsParsedXML = (response) =>
})

export class RNS3 {
static getAwsUrl(options) {
if(options.awsUrl) {
return options.awsUrl;
}

return `s3${options.region ? `-${options.region}` : ''}.amazonaws.com`;
}

static put(file, options) {
options = {
...options,
Expand All @@ -38,7 +44,9 @@ export class RNS3 {
contentType: file.type
}

const url = `https://${options.bucket}.${options.awsUrl || AWS_DEFAULT_S3_HOST}`
const url = options.urlAsPath ?
`https://${RNS3.getAwsUrl(options)}/${options.bucket}` :
`https://${options.bucket}.${RNS3.getAwsUrl(options)}`
const method = "POST"
const policy = S3Policy.generate(options)

Expand Down