Basic S3 access library for Vapor written in Swift
- Add following package to your
Package.swift
:
.Package(url: "https://github.com/manGoweb/S3.git", majorVersion: 2)
-
Run
vapor clean
-
Do
vapor xcode
Import the module import S3
let s3: S3 = try S3(droplet: drop)
let fileData: Data = try s3.get(fileAtPath: "images/image.png")
let s3: S3 = try S3(droplet: drop)
let url = URL.init(fileURLWithPath: "/Users/pro/Dropbox/books/agile-android-software-development.pdf")
try s3.put(fileAtUrl: url, filePath: "books/agile-android-software-development.pdf", accessControl: .publicRead)
let s3: S3 = try S3(droplet: drop)
try s3.delete(fileAtPath: "images/image.png")
Looks like this Config/s3.json
:
{
"accessKey": "{your-AWS-accees-key}",
"secretKey": "{your-AWS-secret-key}",
"bucket": "{bucket-name}"
}
The bucket name is an optional value so you can skip it if you want:
{
"accessKey": "{your-AWS-accees-key}",
"secretKey": "{your-AWS-secret-key}"
}
- Check if you don't need to set your region, it's one of the optional methods on all put methods
- Go to Vapor slack channel and ask for @rafiki270, you can scream at him
- Send a merge request, create an issue, Slack me on Vapor channel, @rafiki270
Your manGoweb.cz team