Skip to content
This repository has been archived by the owner. It is now read-only.

Configure per-service request headers for direct uploads #83

Merged
merged 2 commits into from Jul 30, 2017

Conversation

@javan
Copy link
Member

@javan javan commented Jul 29, 2017

Really fixes #79
Eliminates the need for a direct-upload:before-storage-request hook in #36, re: #79 (comment)

/cc @dixpac

@javan javan requested review from dhh and georgeclaghorn Jul 29, 2017
@@ -68,6 +68,10 @@ def url_for_direct_upload(key, expires_in:, content_type:, content_length:, chec
end
end

def headers_for_direct_upload(key, content_type:, checksum:, **)
{ "Content-Type": content_type, "Content-MD5" => checksum }

This comment has been minimized.

@georgeclaghorn

georgeclaghorn Jul 29, 2017
Member

"Content-Type" => content_type

This comment has been minimized.

@javan

javan Jul 29, 2017
Author Member

Fixed in 042bf7d

assert_equal checksum, details["checksum"]
assert_equal "text/plain", details["content_type"]
assert_match /#{SERVICE_CONFIGURATIONS[:s3][:bucket]}\.s3.(\S+)?amazonaws\.com/, details["direct_upload"]["url"]
assert_equal({ "Content-Type" => "text/plain", "Content-MD5": blob.checksum }, details["direct_upload"]["headers"])

This comment has been minimized.

@georgeclaghorn

georgeclaghorn Jul 29, 2017
Member

checksum instead of blob.checksum?

This comment has been minimized.

@georgeclaghorn

georgeclaghorn Jul 29, 2017
Member

"Content-MD5" => checksum

This comment has been minimized.

@javan

javan Jul 29, 2017
Author Member

Fixed in 042bf7d

end

private
def blob_args
params.require(:blob).permit(:filename, :byte_size, :checksum, :content_type, :metadata).to_h.symbolize_keys
end

def direct_upload_json(blob)
blob.as_json(methods: :signed_id).merge(direct_upload: {

This comment has been minimized.

@georgeclaghorn

georgeclaghorn Jul 29, 2017
Member

Do we need to return a complete JSON representation of the blob now?

This comment has been minimized.

@javan

javan Jul 29, 2017
Author Member

Not technically, but it robustifies the client-side API with a complete set of attributes from the server.

Before:
before
After:
after

@javan javan force-pushed the direct-upload-service-headers branch from 1bae4c0 to 042bf7d Jul 29, 2017
@dixpac
Copy link
Contributor

@dixpac dixpac commented Jul 30, 2017

Looks good to me 👏

@dhh dhh merged commit 39bfc83 into master Jul 30, 2017
2 checks passed
2 checks passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details
@javan javan mentioned this pull request Jul 30, 2017
5 of 5 tasks complete
@javan javan deleted the direct-upload-service-headers branch Jul 30, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

4 participants
You can’t perform that action at this time.