Using MSAL 1.1.24 & making API calls in an iOS app that supports uploading to OneDrive for a year now. Some users reported that they sometimes (not 100% of the time) see their upload fail. The error message is "The request is malformed or incorrect". Attached is a screenshot with the full error message returned by the servers:
Whats is wrong in the URL?
This is how I create the request:
/* REQUEST */
guard let validPathForURL = uploadPath.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed),
let url = URL(string: "\(ODManager.kGraphEndpoint)"+validPathForURL+":/createUploadSession") else {
DLog("Invalid URL")
completion(QSTransferResult.failure(QSTransferError.ResourceNotFound), nil)
return
}
var request = ODManager.shared.createURLRequestWithToken(url: url)
request.httpMethod = "POST"
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
// Conflict management
let fileExistBehavior = fileExistProcedure == .keepBoth ? "rename" : "replace"
let params = ["item": [
"@microsoft.graph.conflictBehavior":fileExistBehavior,
"name":fileName],
"fileSize":fileSize,
] as [String : Any] // name must be the same as the one mentioned in the URL (in other words, the file name must be in both place)
request.httpBody = try! JSONSerialization.data(withJSONObject: params, options: JSONSerialization.WritingOptions())
Finally found the issue, that was as a matter of fact, only happening on business accounts. It turns out that you cannot use the fileSize parameter on these accounts.
More info here: https://stackoverflow.com/a/64225439/2040156
It should be fixed on Microsoft side imho, to avoid a lot of time lost. What's the point of this difference anyway?