jaredramirez/elm-s3/1.1.0

S3

This package helps make uploading file to Amazon S3 quick and easy.

Take a look at the README for an example!

Creating a Config

type alias Config =
Config

Opaque configuration type for S3 requests

{ accessKey : String
, secretKey : String
, bucket : String
, region : String
}
-> Config

Create S3 config with the required files common across all requets

withPrefix : String -> Config -> Config

Add a prefix to the file being uploaded. This is helpful to specify a sub directory to upload the file to.

config |> withPrefix "my/sub/dir/"
withSuccessActionStatus : Int -> Config -> Config

Add a custom success HTTP status. This defaults to 201.

config |> withSuccessActionStatus 200
withAwsS3Host : String -> Config -> Config

Add a custom S3 host. This defaults to s3.amazonaws.com.

config |> withAwsS3Host "customhost.aws.com"
withAcl : String -> Config -> Config

Add a custom acl (Access Control List) for the uploaded document. This defaults to public-read

config |> withAcl "private"
withTimeout : Float -> Config -> Config

Add a timeout to the network request. From the elm-http docs: "The timeout is the number of milliseconds you are willing to wait before giving up."

config |> withTimeout 5000

Uploading a file

type alias FileData =
{ fileName : String
, contentType : String
, file : File
}

All the information needed for a specific file upload.

type alias Response =
{ etag : String
, location : String
, bucket : String
, key : String
}

The response from the upload request.

uploadFileCmd : (Result Error Response -> msg) -> FileData -> Config -> Cmd msg

Upload a file

uploadFileTask : FileData -> Config -> Task Error Response

Upload a file but as a task. This is helpful if you need to upload a file, then get it's location from the Response and send that on your server.

{ toMsg : Result Error Response -> msg
, maybeTracker : Maybe String
, now : Posix
}
-> FileData
-> Config
-> Cmd msg

Upload file via Http.request. Useful if you want to get the tracker but you must provide your own Time.now due to limitations with Http + Task.

uploadFile : FileData -> Config -> (Result Error Response -> msg) -> Cmd msg

Deprecated. Use uploadFileCmd instead