I’m trying to change the user profile picture using Firebase Storage, I already have the URL from the image, but when trying to change it I receive this error:
Optional(<NSHTTPURLResponse: 0x283a91000> { URL: https://tvayuda.auth0.com/api/v2/users/000353.e663e38b6fb34029bc51fefc1371bd46.2343 } { Status Code: 400, Headers {
"Cache-Control" = (
"no-cache"
);
"Content-Type" = (
"application/json; charset=utf-8"
);
Date = (
"Thu, 31 Dec 2020 19:54:32 GMT"
);
Server = (
cloudflare
);
"Strict-Transport-Security" = (
"max-age=31536000"
);
Vary = (
"origin,accept-encoding"
);
"cf-cache-status" = (
DYNAMIC
);
"cf-ray" = (
"60a68d8f9c0b167f-PHX"
);
"cf-request-id" = (
075bf6cdc20000167f2db09000000001
);
"expect-ct" = (
"max-age=604800, report-uri=\"https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct\""
);
"ot-baggage-auth0-request-id" = (
60a68d8f9c0b167f
);
"ot-tracer-sampled" = (
true
);
"ot-tracer-spanid" = (
7fa1523429d712c8
);
"ot-tracer-traceid" = (
769f4f440a62bbce
);
"x-content-type-options" = (
nosniff
);
} })
And this is the code I’m using:
let headers = [
"authorization": "Bearer [token]",
"content-type": "application/json"
]
let parameters = ["user_metadata": ["picture": "[imgeurl - from firebase"]] as [String : Any]
let postData = try! JSONSerialization.data(withJSONObject: parameters, options: [])
let request = NSMutableURLRequest(url: NSURL(string: "https://tvayuda.auth0.com/api/v2/users/\(userID ?? "")")! as URL,
cachePolicy: .useProtocolCachePolicy,
timeoutInterval: 10.0)
request.httpMethod = "PATCH"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data
let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
if (error != nil) {
print(error)
} else {
let httpResponse = response as? HTTPURLResponse
print(httpResponse)
}
})
dataTask.resume()