Skip to content

Commit

Permalink
MD5 Hash Correction
Browse files Browse the repository at this point in the history
Change Content-MD5 calculation from hexString to base64EncodedString
  • Loading branch information
anthonycastelli authored Apr 30, 2018
2 parents 4dbbc94 + 40fcb26 commit 959c70e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 1 addition & 2 deletions Sources/S3Storage/S3 Signer/S3Adapter+Networking.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ extension S3Adapter {
var updatedHeaders = self.updateHeaders(headers, url: url, longDate: dates.long, bodyDigest: bodyDigest)

if httpMethod == .PUT && payload.isBytes {
// TODO: Figure out why S3 would fail with this
updatedHeaders["Content-MD5"] = try MD5.hash(payload.bytes).hexEncodedString()
updatedHeaders["Content-MD5"] = try MD5.hash(payload.bytes).base64EncodedString()
}

updatedHeaders["Authorization"] = try self.generateAuthHeader(httpMethod, url: url, headers: updatedHeaders, bodyDigest: bodyDigest, dates: dates)
Expand Down
3 changes: 3 additions & 0 deletions Sources/S3Storage/S3Adapter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ extension S3Adapter {
request.http.body = HTTPBody(data: content)
request.http.url = url
return try client.respond(to: request).map(to: ObjectInfo.self) { response in
guard response.http.status == .ok else {
throw S3AdapterError(identifier: "create", reason: "Couldnt not create the file.", source: .capture())
}
return ObjectInfo(name: url.lastPathComponent, prefix: nil, size: nil, etag: "MD5-Hash", lastModified: Date())
}
}
Expand Down

0 comments on commit 959c70e

Please sign in to comment.