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

Storage Content-Type #27

Merged
merged 9 commits into from
Jun 11, 2016
Merged

Storage Content-Type #27

merged 9 commits into from
Jun 11, 2016

Conversation

brendanhay
Copy link
Owner

@brendanhay brendanhay commented Jun 10, 2016

Changes the custom Servant multipart/related instances to allow passing in of the non-root object payload's Content-Type.

This Content-Type (of type HttpMedia from http-media) is passed in as an additional parameter to upload.

The following example would align with the Google Storage documentation:

example = do
    l <- newLogger Debug stdout
    e <- newEnv <&> (envLogger .~ l) . allow storageReadWriteScope

    -- This will guess the MIME type as "image/jpeg" due to the file extension.
    b <- sourceBody "/path/to/image.jpg"

    -- An example of explicitly setting the MIME type would be:
    -- b <- sourceBody "/path/to/image.jpg" <&> bodyContentType .~ "image" // "png"

    let bkt = "bucket-name"
        key = "object-key.jpg"

    runResourceT . runGoogle e $ do
        _ <- upload (objectsInsert bkt object' & oiName ?~ key) b
        _ <- download (objectsGet bkt key)
        pure ()
POST https://www.googleapis.com/upload/storage/v1/b/myBucket/o?uploadType=multipart HTTP/1.1
Authorization: Bearer [YOUR_AUTH_TOKEN]
Content-Type: multipart/related; boundary=foo_bar_baz
Content-Length: [NUMBER_OF_BYTES_IN_ENTIRE_REQUEST_BODY]

--foo_bar_baz
Content-Type: application/json; charset=UTF-8

{
  "name": "myObject"
}

--foo_bar_baz
Content-Type: image/jpeg

[JPEG_DATA]
--foo_bar_baz--

Fixes #16.

@brendanhay brendanhay force-pushed the feature/storage-content-type branch 2 times, most recently from 76fd734 to 40dd32b Compare June 11, 2016 10:55
@brendanhay brendanhay force-pushed the feature/storage-content-type branch from 40dd32b to e437f32 Compare June 11, 2016 12:22
@brendanhay brendanhay merged commit c63095b into develop Jun 11, 2016
@brendanhay brendanhay deleted the feature/storage-content-type branch June 11, 2016 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant