Skip to content
This repository was archived by the owner on Sep 15, 2025. It is now read-only.

Commit f335202

Browse files
authored
Fix an XMLRPC uploading file issue (#734)
2 parents 4df2b39 + 02a1230 commit f335202

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

WordPressKit/HTTPRequestBuilder.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ final class HTTPRequestBuilder {
229229
} else {
230230
let data = try encoder.dataEncoded()
231231
request.setValue("\(data.count)", forHTTPHeaderField: "Content-Length")
232-
return try .left(encoder.dataEncoded())
232+
return .left(data)
233233
}
234234
}
235235
}

WordPressKitTests/Utilities/HTTPRequestBuilderTests.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,4 +412,18 @@ class HTTPRequestBuilderTests: XCTestCase {
412412
)
413413
}
414414

415+
func testXMLRPCUpload() throws {
416+
let file = try XCTUnwrap(Bundle(for: type(of: self)).url(forResource: "me-settings-success", withExtension: "json"))
417+
let fileContentBase64 = try Data(contentsOf: file).base64EncodedString()
418+
let fileStream = try XCTUnwrap(InputStream(url: file))
419+
let request = try HTTPRequestBuilder(url: URL(string: "https://w.org/xmlrpc.php")!)
420+
.method(.post)
421+
.body(xmlrpc: "wp.uploadFile", parameters: ["username", "passowrd", fileStream])
422+
.build(encodeBody: true)
423+
424+
let xmlrpcContent = try XCTUnwrap(request.httpBodyText)
425+
let filePart = "<base64>" + fileContentBase64 + "</base64>"
426+
XCTAssertTrue(xmlrpcContent.contains(filePart))
427+
}
428+
415429
}

0 commit comments

Comments
 (0)