Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Progress closure seems broken #295

Open
LinusGeffarth opened this issue Jun 15, 2018 · 0 comments · May be fixed by #296
Open

Progress closure seems broken #295

LinusGeffarth opened this issue Jun 15, 2018 · 0 comments · May be fixed by #296

Comments

@LinusGeffarth
Copy link

LinusGeffarth commented Jun 15, 2018

I'm using the following code to upload an image in base64 format and I would like to track that upload's progress:

var r  = URLRequest(url: URL(string: apiURL+"images")!)
r.httpMethod = "POST"
r.setValue("multipart/form-data", forHTTPHeaderField: "Content-Type")
r.setValue(accessToken, forHTTPHeaderField: "Authorization")
r.httpBody = {
    var body = Data()
    let boundary = "Boundary-\(UUID().uuidString)"
    let boundaryPrefix = "--\(boundary)\r\n"
    
    for (key, value) in ["file": imageData] {
        body.append(string: boundaryPrefix)
        body.append(string: "Content-Disposition: form-data; name=\"\(key)\"\r\n\r\n")
        body.append(string: "\(value)\r\n")
    }
    body.append(string: "\r\n")
    body.append(string: "--".appending(boundary.appending("--")))
    
    return body
}()
let task = HTTP(r)
task.progress = { progress in
    print(progress)
}
task.run { (response) in
    print(response.text)
}

What this prints:

1.0
-30.0
"{some json}"

Do you know why that is? The image's size is 1.5mB, and my upload speed is around 300kB/s so it can't be at 1 immediately, not to speak about the progress of -30...

Thanks!

@LinusGeffarth LinusGeffarth linked a pull request Jun 15, 2018 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant