Skip to content
master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 

S3Policy

Generate your S3 upload policies in Swift.

For signing the policy you can use https://github.com/darkFunction/S3SignerAWS

Example use

Here we create the encoded policy and sign it using S3SignerAWS.

    import S3SignerAWS
    import S3Policy

    ...

    let timestamp = Date().iso8601(compact: true)
    let signer = S3Signer(accessKey: <awsAccessKey>, secretKey: <awsSecretKey>, region: <region>)
    let credential = "\(<awsAccessKey>)/\(signer.credentialScope(timeStampShort: timestamp.short))"
        
    let policy = S3Policy(
        expiration: <expiration>,
        conditions: [
            .exact(.bucket, <bucket>),
            .startsWith(.key, <path>),
            .exact(.acl, <acl>),
            .startsWith(.contentType, "image/"),
            .contentLength(0...<maxBytes>),
            .exact(.xAmzAlgorithm, SigningAlgorithm.hmacSha256.rawValue),
            .exact(.xAmzCredential, credential),
            .exact(.xAmzDate, timestamp.full)
        ]
    )

    let policyBase64 = try policy.json().base64()
    let policySignature = try signer.createSignature(stringToSign: policyBase64, timeStampShort: timestamp.short)

About

Generate S3 policy documents in Swift

Resources

Packages

No packages published

Languages