|
1 | 1 | /*
|
2 | 2 | * --------------------------------------------------------------------------------
|
3 | 3 | * <copyright company="Aspose" file="ObjectSerializer.swift">
|
4 |
| - * Copyright (c) 2020 Aspose.Words for Cloud |
| 4 | + * Copyright (c) 2021 Aspose.Words for Cloud |
5 | 5 | * </copyright>
|
6 | 6 | * <summary>
|
7 | 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
@@ -176,6 +176,39 @@ class ObjectSerializer {
|
176 | 176 | return result;
|
177 | 177 | }
|
178 | 178 |
|
| 179 | + // Get multipart by name |
| 180 | + public static func getMultipartByName(multipart: [ResponseFormParam], name: String) throws -> ResponseFormParam { |
| 181 | + for part in multipart { |
| 182 | + let disposition = part.getHeaders()["Content-Disposition"]; |
| 183 | + if (disposition == nil) { |
| 184 | + continue; |
| 185 | + } |
| 186 | + |
| 187 | + var partName: String? = nil; |
| 188 | + for componentRawData in disposition!.components(separatedBy: ";") { |
| 189 | + let componentData = componentRawData.trimmingCharacters(in: .whitespacesAndNewlines); |
| 190 | + if (!componentData.isEmpty) { |
| 191 | + let componentDataParts = componentData.split(separator: "="); |
| 192 | + if (componentDataParts.count == 2) { |
| 193 | + let componentKey = componentDataParts[0].trimmingCharacters(in: .whitespaces); |
| 194 | + let componentValue = componentDataParts[1].trimmingCharacters(in: .whitespaces); |
| 195 | + if (componentKey == "name") { |
| 196 | + partName = componentValue; |
| 197 | + break; |
| 198 | + } |
| 199 | + } |
| 200 | + } |
| 201 | + } |
| 202 | + |
| 203 | + if (partName != nil && partName == name) |
| 204 | + { |
| 205 | + return part; |
| 206 | + } |
| 207 | + } |
| 208 | + |
| 209 | + throw WordsApiError.invalidMultipartResponse(message: "Part " + name + " not found in multipart data."); |
| 210 | + } |
| 211 | + |
179 | 212 | // Split data into parts
|
180 | 213 | public static func splitData(data: Data, separator: Data) -> [Data] {
|
181 | 214 | let endIndex = separator.count;
|
|
0 commit comments