Moya上传图片和文件例子

上传图片

case let .uploadimg(imageData: data):
            let timestamp = Int(Date().timeIntervalSince1970)
            let fileName = (MD5("\(timestamp)") ?? "errorImageName") + ".png"
            let formData = Moya.MultipartFormData.init(provider: .data(data),
                                                       name: "file",
                                                   fileName: fileName,
                                                   mimeType: "image/jpeg")
            return .uploadMultipart([formData])
            
       

上传文件

 case let .uploadContract(imageData: data):
            let timestamp = Int(Date().timeIntervalSince1970)
            let fileName = (MD5("\(timestamp)") ?? "errorFileName") + ".docx"
            let type = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
            let formData = Moya.MultipartFormData.init(provider: .data(data),
                                                       name: "file",
                                                   fileName: fileName,
                                                   mimeType:type)

你可能感兴趣的:(Moya上传图片和文件例子)