freshOS / ws-deprecated

⚠️ Deprecated - (in favour of Networking) :cloud: Elegantly connect to a JSON api. (Alamofire + Promises + JSON Parsing)
MIT License
353 stars 32 forks source link

Handle double parameters for multipart request #43

Closed LivioGama closed 7 years ago

LivioGama commented 7 years ago

I send a multipart request with a picture and other parameters. The string ones work but the Double ones don't. I checked the file WSRequest.swift in method func sendMultipartRequest(_ resolve: @escaping (_ result: (Int, [AnyHashable: Any], JSON)) -> Void, reject: @escaping (_ error: Error) -> Void, progress:@escaping (Float) -> Void)

I add the double case like this :

for (key, value) in self.params {
    if let int = value as ? Int {
        let str = "\(int)"
        if let d = str.data(using: String.Encoding.utf8) {
            formData.append(d, withName: key)
        }
    } else if
    let double = value as ? Double {
        let str = "\(double)"
        if let d = str.data(using: String.Encoding.utf8) {
            formData.append(d, withName: key)
        }
    } else {
        if let str = value as ? String, let data = str.data(using: String.Encoding.utf8) {
            formData.append(data, withName: key)
        }
    }
}

Would be cool if you could fix it officially

maxkonovalov commented 7 years ago

Hello @LivioGama, thanks for the catch! I'd fix this issue with a more generic approach - see #44 @s4cha what do you think?

LivioGama commented 7 years ago

Totally agree for a more generic approach, this is what I was thinking about, thanks !

s4cha commented 7 years ago

@maxkonovalov The fix looks good to me ! Thanks for being so reactive as usual :)

s4cha commented 7 years ago

Should be solved in 2.0.4 https://github.com/freshOS/ws/releases/tag/2.0.4 Kudos to you guys 👏