如何使用 MS Graph API 执行可恢复上传到 SharePoint 站点(非根)子文件夹 [英] How to perform a resumable Upload to a SharePoint Site (Not Root) Subfolder using MS Graph API

查看:97
本文介绍了如何使用 MS Graph API 执行可恢复上传到 SharePoint 站点(非根)子文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

文档:

https://docs.microsoft.com/en-us/graph/api/driveitem-createuploadsession?view=graph-rest-1.0

我能够使用站点/域/驱动器 api 获取子站点的驱动器 ID.使用这个和 driveId/root/children 我可以确认这个驱动器上的几个文件夹.

I am able to get the Drive ID of the sub site using the sites/domain/drives api. Using this and the driveId/root/children I can confirm several folders on this drive.

如果我使用 API POST/drives/{driveId}/items/{itemId}/createUploadSession 将 driveId 替换为驱动器 ID,将 itemId 替换为文件夹 ID,则会出现以下错误

If I use the API POST /drives/{driveId}/items/{itemId}/createUploadSession replacing the driveId with the drive ID and the itemId with the folder ID I get the following error

{
  "error": {
    "code": "nameAlreadyExists",
    "message": "Cannot create an upload session on a folder",
    "innerError": {
      "request-id": "609e17d5-b3f8-455d-9d0f-4849872d8cfa",
      "date": "2020-02-25T20:31:33"
    }
  }
}

如果文件夹 ID 不是 ItemID,那么 ItemID 是什么?如何指定要将文件保存到的文件夹?还是子文件夹或文件夹?没有一个选项让我使用 ItemID 以外的任何东西

If the folder ID is not the ItemID, what is an ItemID ? How do I specify the folder that I want to save a file to? Or a subfolder or folders? None of the otpions let me use anything other than ItemID

POST /drives/{driveId}/items/{itemId}/createUploadSession
POST /groups/{groupId}/drive/items/{itemId}/createUploadSession
POST /me/drive/items/{itemId}/createUploadSession
POST /sites/{siteId}/drive/items/{itemId}/createUploadSession
POST /users/{userId}/drive/items/{itemId}/createUploadSession 

推荐答案

您问题中的请求选项只能用于通过使用文档的 id 上传现有文档的新版本.文件夹没有可以用较新版本替换的文档.因此,无法为文件夹创建上传会话.您需要在文件夹 id 之后指定文件名作为相对路径,以便为文件夹中的新文件创建上传会话:

The request options in your question can only be used to upload a new version of an already existing document by using the id of the document. A folder does not have a document, that can be replace with a newer version. Therefore, it is not possible to create an upload session for a folder. You need to specify the name of the file as a relative path after the folder id in order to create an upload session for a new file in the folder:

https://graph.microsoft.com/v1.0/sites/{siteId}/drives/{driveId}/items/{folderId}:/{fileNameUploadFile}:/createUploadSession

您也可以使用文件夹名称代替文件夹 ID:

You can also use the folder name instead of the folder id:

https://graph.microsoft.com/v1.0/sites/{siteId}/drives/{driveId}/root:/{folderName}/{fileNameUploadFile}:/createUploadSession

这篇关于如何使用 MS Graph API 执行可恢复上传到 SharePoint 站点(非根)子文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆