gpt4 book ai didi

swift - 如何使用 Alamofire 从相机胶卷上传图像

转载 作者:行者123 更新时间:2023-11-30 13:52:09 25 4
gpt4 key购买 nike

我在使用 Alamofire 上传图像时遇到问题。问题很简单 - 我不知道如何获取所选图像的 fileURL(NSURL) 。以下是来自 Alamofire GitHub 的简单代码:

Alamofire.upload(
.POST,
"myCustomServerURL",
multipartFormData: { multipartFormData in
multipartFormData.appendBodyPart(data: "_formname".dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)!, name :"default")
//How to get fireURL?
multipartFormData.appendBodyPart(fileURL: imageURL, name: "unicorn")
},
encodingCompletion: { encodingResult in
switch encodingResult {
case .Success(let upload, _, _):
upload.responseJSON { response in
debugPrint(response)
}
case .Failure(let encodingError):
print(encodingError)
}
}
)

获取本地文件的 NSURL 的常用方法是什么?

最佳答案

您从选择器中获取 UIImage 实例。获取图像并将其写入磁盘 jpg ( UIImageJPEGRepresentation ) 或 png ( UIImagePNGRepresentation ) 并使用存储图像的文件 URL。

关于swift - 如何使用 Alamofire 从相机胶卷上传图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34129981/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com