[英]How to upload image in Swift using Moya?
I have a project where Users select Images from their gallery or snap and it is supposed to be uploaded to a remote server. 我有一个项目,用户可以从其图库或快照中选择图像,并且应该将其上载到远程服务器。
Now if I try to upload with a static image that I put in my xcode
, The image gets uploaded but the moment I use my ImagePicker
and select the Image and pass it to the ImageView
, the photo shows but fails to upload to the server. 现在,如果我尝试使用放入
xcode
的静态图像进行上传,该图像将被上传,但是当我使用ImagePicker
并选择Image并将其传递给ImageView
,该照片将显示,但无法上传至服务器。 The app does not crash, the image upload just does not go. 该应用程序不会崩溃,只是无法上传图像。 Any reason why?
有什么原因吗? and any help would be appreciated
任何帮助将不胜感激
NetworkAdapter.instance.uploadImage(status: "user", image: Img.image).subscribe(onNext: { check in
print("CHECKOUT NOW \(check)")
}, onError: { error in
print("CHECKOUT NOW \(error.localizedDescription)")
}).disposed(by: disposeBag)
I am using Moya
for API call 我正在使用
Moya
进行API调用
case .uploadImage(let data):
let imageData = data.image.jpegData(compressionQuality: 1.0)
let memberIdData = "\(data.status)".data(using: String.Encoding.utf8) ?? Data()
var formData: [Moya.MultipartFormData] = [Moya.MultipartFormData(provider: .data(imageData!), name: "image", fileName: "user.jpeg", mimeType: "image/jpeg")]
Try this: Change Jpeg data. 尝试以下操作:更改Jpeg数据。
case .uploadImage(let data):
let imageData = data.image.jpegData(compressionQuality: 0)
let memberIdData = “\(data.status)“.data(using: String.Encoding.utf8) ?? Data()
var formData: [Moya.MultipartFormData] = [Moya.MultipartFormData(provider: .data(imageData!), name: “image”, fileName: “user.jpeg”, mimeType: “image/jpeg”)]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.