0

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:

enter image description here

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())

The server returning the issue: enter image description here

vomi
  • 993
  • 8
  • 18
  • Can you show what your request looks like? – Brad Jan 04 '23 at 22:34
  • Just added code to show how it is built. I cannot reproduce the issue, only some users seem to have it, but I could not yet identify a specific workflow triggering the issue. – vomi Jan 12 '23 at 09:38
  • I drilled in a little more and I'm now confident the reason for the failure is what I stated in my answer. What's unclear based on your code is how that could be the case. I know `JSONSerialization` does support sorting, but 1) you need to specify the option and 2) it wouldn't result in non-deterministic behavior. If it's not something in the app the only other possibility is some other entity applying the sort, but given it's an HTTPS request that also seems unlikely. – Brad Jan 25 '23 at 19:36
  • @Brad, the users reporting the issue have one common point: they upload to a German server (cfr screenshot added to the main post). Could it be a lead? – vomi Jan 31 '23 at 09:01
  • @Brad another user reported today, the same issue, coming from the very same Germany West Central server. Could it be the issue? – vomi Jun 28 '23 at 12:34

1 Answers1

0

I'm going to take a stab at this... I think when it's failing the @name.conflictBehavior annotation is NOT the first property in the JSON document provided to the service (it doesn't actually have to be first - it can be after another instance annotations, but NOT properties). Now the fact that it doesn't happen often is a little odd... is it possible the annotation is only added on occasion (e.g. when a conflict is detected you pop up UI to ask if the user wants to overwrite)?

Brad
  • 4,089
  • 2
  • 16
  • 26
  • Thank you for your answer. I added a small portion of code showing how I build the request, including the conflict management (i.e. : `@microsoft.graph.conflictBehavior`). It is always first in the parameters. (The user is not prompted in case of conflict, the procedure (rename/replace) is a global parameter. – vomi Jan 12 '23 at 09:37