使用 Microsoft Graph API 进行 OneDrive 上传的 CreateUploadSession:请求格式错误或不正确

问题描述 投票:0回答:2

使用 MSAL 1.1.24 并在支持上传到 OneDrive 一年的 iOS 应用程序中进行 API 调用。 一些用户报告说,他们有时(不是 100% 的时间)发现上传失败。 错误消息是“请求格式错误或不正确”。 附件是服务器返回的完整错误消息的屏幕截图:

网址有什么问题吗?

这就是我创建请求的方式:

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

服务器返回问题:

microsoft-graph-api onedrive microsoft-graph-files
2个回答
0
投票

我要尝试一下......我认为当它失败时,

@name.conflictBehavior
注释不是提供给服务的JSON文档中的第一个属性(它实际上不必是第一个 - 它可以在另一个实例注释之后,但不是属性)。现在,这种情况并不经常发生的事实有点奇怪......是否有可能仅偶尔添加注释(例如,当检测到冲突时,您会弹出 UI 询问用户是否想要覆盖)?


0
投票

终于找到问题了,事实上,这个问题只发生在企业账户上。 事实证明,您无法在这些帐户上使用 fileSize 参数。

更多信息在这里:https://stackoverflow.com/a/64225439/2040156

恕我直言,它应该在微软方面修复,以避免浪费大量时间。无论如何,这种差异有什么意义?

© www.soinside.com 2019 - 2024. All rights reserved.