Skip to content

Commit 3b79dee

Browse files
committed
Add form-data file container
1 parent f7e60ae commit 3b79dee

4 files changed

Lines changed: 31 additions & 21 deletions

File tree

Example/Demo.xcodeproj/project.pbxproj

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@
154154
1D2CCCE220BD3F56002D0ACC /* Sources */,
155155
1D2CCCE320BD3F56002D0ACC /* Frameworks */,
156156
1D2CCCE420BD3F56002D0ACC /* Resources */,
157-
B3E033231D1ABE0A13F32686 /* [CP] Embed Pods Frameworks */,
157+
6A8E04F756F17B2B6C20B160 /* [CP] Embed Pods Frameworks */,
158158
);
159159
buildRules = (
160160
);
@@ -263,39 +263,39 @@
263263
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
264264
showEnvVarsInLog = 0;
265265
};
266-
A7870D15C3A8DD987B733581 /* [CP] Check Pods Manifest.lock */ = {
266+
6A8E04F756F17B2B6C20B160 /* [CP] Embed Pods Frameworks */ = {
267267
isa = PBXShellScriptBuildPhase;
268268
buildActionMask = 2147483647;
269269
files = (
270270
);
271-
inputPaths = (
272-
"${PODS_PODFILE_DIR_PATH}/Podfile.lock",
273-
"${PODS_ROOT}/Manifest.lock",
271+
inputFileListPaths = (
272+
"${PODS_ROOT}/Target Support Files/Pods-Demo/Pods-Demo-frameworks-${CONFIGURATION}-input-files.xcfilelist",
274273
);
275-
name = "[CP] Check Pods Manifest.lock";
276-
outputPaths = (
277-
"$(DERIVED_FILE_DIR)/Pods-DemoTests-checkManifestLockResult.txt",
274+
name = "[CP] Embed Pods Frameworks";
275+
outputFileListPaths = (
276+
"${PODS_ROOT}/Target Support Files/Pods-Demo/Pods-Demo-frameworks-${CONFIGURATION}-output-files.xcfilelist",
278277
);
279278
runOnlyForDeploymentPostprocessing = 0;
280279
shellPath = /bin/sh;
281-
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
280+
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Demo/Pods-Demo-frameworks.sh\"\n";
282281
showEnvVarsInLog = 0;
283282
};
284-
B3E033231D1ABE0A13F32686 /* [CP] Embed Pods Frameworks */ = {
283+
A7870D15C3A8DD987B733581 /* [CP] Check Pods Manifest.lock */ = {
285284
isa = PBXShellScriptBuildPhase;
286285
buildActionMask = 2147483647;
287286
files = (
288287
);
289-
inputFileListPaths = (
290-
"${PODS_ROOT}/Target Support Files/Pods-Demo/Pods-Demo-frameworks-${CONFIGURATION}-input-files.xcfilelist",
288+
inputPaths = (
289+
"${PODS_PODFILE_DIR_PATH}/Podfile.lock",
290+
"${PODS_ROOT}/Manifest.lock",
291291
);
292-
name = "[CP] Embed Pods Frameworks";
293-
outputFileListPaths = (
294-
"${PODS_ROOT}/Target Support Files/Pods-Demo/Pods-Demo-frameworks-${CONFIGURATION}-output-files.xcfilelist",
292+
name = "[CP] Check Pods Manifest.lock";
293+
outputPaths = (
294+
"$(DERIVED_FILE_DIR)/Pods-DemoTests-checkManifestLockResult.txt",
295295
);
296296
runOnlyForDeploymentPostprocessing = 0;
297297
shellPath = /bin/sh;
298-
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Demo/Pods-Demo-frameworks.sh\"\n";
298+
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
299299
showEnvVarsInLog = 0;
300300
};
301301
BD48511BE9E153A767A947C2 /* [CP] Embed Pods Frameworks */ = {

Example/Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
PODS:
2-
- RMHttp (1.5.0)
2+
- RMHttp (1.6.0)
33

44
DEPENDENCIES:
55
- RMHttp (from `../`)
@@ -9,7 +9,7 @@ EXTERNAL SOURCES:
99
:path: "../"
1010

1111
SPEC CHECKSUMS:
12-
RMHttp: fce70e5558179acde55ccb99ef7e0eeb1e9b3314
12+
RMHttp: 56238b4b0cf7348bc679b1783326ad01b2dda349
1313

1414
PODFILE CHECKSUM: 823b377b5b04076a920183be778a664128b2ad2d
1515

RMHttp/Classes/RMRequest.swift

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,18 +146,28 @@ extension RMRequest {
146146
}
147147

148148
// Form-Data from params
149-
public func setFormData(fields: [String : Any]) {
149+
public func setFormData(fields: [String : Any], _ files: [RMFormDataFile]? = nil) {
150150
let boundary = UUID().uuidString
151151
if urlRequest.value(forHTTPHeaderField: HeaderField.contentType.rawValue) == nil {
152-
urlRequest.setValue("\(HeaderValue.FormData.rawValue)\(boundary)",
153-
forHTTPHeaderField: HeaderField.contentType.rawValue)
152+
urlRequest.setValue("\(HeaderValue.FormData.rawValue)\(boundary)", forHTTPHeaderField: HeaderField.contentType.rawValue)
154153
}
155154
var data = Data()
156155
for (key, value) in fields {
157156
data.append("\r\n--\(boundary)\r\n".data(using: .utf8)!)
158157
data.append("Content-Disposition: form-data; name=\"\(key)\"\r\n\r\n".data(using: .utf8)!)
159158
data.append("\(value)".data(using: .utf8)!)
160159
}
160+
161+
// Add File fields (optional)
162+
if files != nil {
163+
for file in files! {
164+
data.append("\r\n--\(boundary)\r\n".data(using: .utf8)!)
165+
data.append("Content-Disposition: form-data; name=\"\(file.fieldName)\"; filename=\"\(file.fileName)\"\r\n".data(using: .utf8)!)
166+
data.append("Content-Type: \(file.mimeType)\r\n\r\n".data(using: .utf8)!)
167+
data.append(file.file) // In data representation
168+
data.append("\r\n--\(boundary)--\r\n".data(using: .utf8)!)
169+
}
170+
}
161171
self.urlRequest.httpBody = data // One time set data body
162172
}
163173

0 commit comments

Comments
 (0)