You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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!
The text was updated successfully, but these errors were encountered:
I'm using the following code to upload an image in base64 format and I would like to track that upload's progress:
What this prints:
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!
The text was updated successfully, but these errors were encountered: