Skip to content

Commit b6d9d10

Browse files
Merge pull request #38 from tkey/bulk_stream_multipart
fix: use multipart request for bulk_set_stream
2 parents 9c9b48b + 2c801af commit b6d9d10

File tree

2 files changed

+15
-21
lines changed

2 files changed

+15
-21
lines changed

Sources/ThresholdKey/StorageLayer.swift

+14-20
Original file line numberDiff line numberDiff line change
@@ -51,29 +51,23 @@ public final class StorageLayer {
5151
request.addValue("Content-Type", forHTTPHeaderField: "Access-Control-Allow-Headers")
5252

5353
if urlString.split(separator: "/").last == "bulk_set_stream" {
54-
// let boundary = UUID().uuidString;
55-
// request.addValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")
56-
request.addValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
54+
let boundary = "Boundary-\(UUID().uuidString)"
55+
request.addValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")
5756

5857
let json = try! JSONSerialization.jsonObject(with: dataString.data(using: String.Encoding.utf8)!, options: .allowFragments) as! [[String: Any]]
59-
60-
// for item in json {
61-
// let dataItem = try! JSONSerialization.data(withJSONObject: item, options: .prettyPrinted)
62-
// requestData.append(StorageLayer.createMultipartBody(data: dataItem, boundary: boundary, file: "multipartData"))
63-
// }
64-
65-
var form_data: [String] = []
66-
67-
// urlencoded item format: "(key)=(self.percentEscapeString(value))"
68-
for (index, element) in json.enumerated() {
69-
let json_elem = try! JSONSerialization.data(withJSONObject: element, options: .withoutEscapingSlashes)
70-
let json_escaped_string = StorageLayer.percentEscapeString(string: String(data: json_elem, encoding: .utf8)!)
71-
let final_string = String(index) + "=" + json_escaped_string
72-
form_data.append(final_string)
58+
59+
var body_data = Data()
60+
61+
for (index, item) in json.enumerated() {
62+
body_data.append("--\(boundary)\r\n".data(using: .utf8)!)
63+
body_data.append("Content-Disposition: form-data; name=\"\(index)\"\r\n\r\n".data(using: .utf8)!)
64+
65+
let dataItem = String(data: try! JSONSerialization.data(withJSONObject: item), encoding: .utf8)!
66+
body_data.append("\(dataItem)\r\n".data(using: .utf8)!)
7367
}
74-
let body_data = form_data.joined(separator: "&")
75-
76-
request.httpBody = body_data.data(using: String.Encoding.utf8)
68+
body_data.append("--\(boundary)--\r\n".data(using: .utf8)!)
69+
70+
request.httpBody = body_data
7771
} else {
7872
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
7973
request.httpBody = dataString.data(using: String.Encoding.utf8)

tkey-mpc-swift.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |spec|
22
spec.name = "tkey-mpc-swift"
3-
spec.version = "4.0.0"
3+
spec.version = "4.0.1"
44
spec.platform = :ios, "14.0"
55
spec.summary = "SDK allows you to create threshold key setup natively with multiparty computation support"
66
spec.homepage = "https://web3auth.io/"

0 commit comments

Comments
 (0)