ios - 如何发送[字符串:Any] dictionary in multipart API?

标签 ios swift alamofire alamofireimage

我正在尝试使用 Alamofire 和 [String:Any] 参数发送多部分图像数据,我只能发布 [String:String] 参数

For [String:String] 的做法类似于 https://stackoverflow.com/a/40440371/4466607

但现在我必须发帖: [ PayLoad ],我必须使用 image 键发送图像,我已经在这样做了。

在 postman 中它工作正常 enter image description here

问题: 我如何在 Swift 中使用字典类型 [String:Any] 发布图像 请帮忙

最佳答案

If your value is Any type then check this may be it helps you.

for (key, value) in params {
  let paramsData:Data = NSKeyedArchiver.archivedData(withRootObject: value)
  formData.append(paramsData, withName: key)
}

关于ios - 如何发送[字符串:Any] dictionary in multipart API?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56438184/

相关文章:

ios - 使用 Alamofire 上传图片以及其他字符串数据

ios - 如何使用 post 方法从登录功能将 JSON 数据传递到另一个 View Controller ?

ios - 了解 IOS8 尺寸等级

ios - 使用 JSONDecoder 后如何正确调用属性

返回选择器字典的 Swift 协议(protocol)

swift - 在 SwiftUI (Xcode 12) 中折叠侧边栏

ios - 非续订订阅是否需要还原按钮?

ios - ios有 overdraw 问题吗

java - 用不同的颜色显示国家

ios - 从 API 传递的图像未快速显示在页面 View 容器中