简体   繁体   English

Microsoft Graph API - 如何将附件上传到列表项

[英]Microsoft Graph API - How to upload attachments to a list item

This question has been asked before with not much success. 之前有人问过这个问题,但没有取得多大成功。

The documentation is totally unclear too.文档也完全不清楚。 It implies that to create a new list item one would do the following .这意味着要创建一个新的列表项,将执行以下操作 But doesn't give a specific example on attachments.但没有给出附件的具体例子。

The listitem documentation has a sneaky caveat right at the end which says that files/document libraries are treated as driveitems: listitem 文档在末尾有一个偷偷摸摸的警告,它说文件/文档库被视为驱动器项目:

For document libraries, the driveItem relationship exposes the listItem as a driveItem对于文档库,driveItem 关系将 listItem 公开为 driveItem

Right, so does that mean that all files are then related to driveitems?是的,这是否意味着所有文件都与驱动项目相关? It seems closer as the driveitem docs talk about the following example (indicating site-related content which is SharePoint)driveitem 文档谈论以下示例时,它似乎更接近(指示与站点相关的内容,即 SharePoint)

PUT /sites/{site-id}/drive/items/{parent-id}:/{filename}:/content PUT /sites/{site-id}/drive/items/{parent-id}:/{filename}:/content

But the above route doesn't specify a list-id either an item-id.但是上面的路由既没有指定 list-id 也没有指定 item-id。 So how does that fit in?那么它是如何适应的呢?

Which route do we hit to upload attachments on a list item?我们点击哪条路线来上传列表项上的附件? I have tried numerous requests:我尝试了很多请求:

PUT - https://graph.microsoft.com/v1.0/sites/root/lists/2696fba7-2cc5-482f-805e-a3dbf853e5e9/items/1/content PUT - https://graph.microsoft.com/v1.0/sites/root/lists/2696fba7-2cc5-482f-805e-a3dbf853e5e9/items/1/content

PUT - https://graph.microsoft.com/v1.0/sites/root/drive/items/1/createUploadSession (not list id though?) PUT - https://graph.microsoft.com/v1.0/sites/root/drive/items/1/createUploadSession (虽然不是列表 ID?)

To upload an small item (<4MB) into a Sharepoint Online document library or list which is not the default library, you can youse the following url syntax:要将小项目 (<4MB) 上传到非默认库的 Sharepoint Online 文档库或列表,您可以使用以下 url 语法:

https://graph.microsoft.com/v1.0/sites/ {SITE-ID}/drives/{DRIVE-ID}/root:/{FILENAME}:/content https://graph.microsoft.com/v1.0/sites/ {SITE-ID}/drives/{DRIVE-ID}/root:/{FILENAME}:/content

  • {SITE-ID}: the id of sp site {SITE-ID}:sp站点的id
  • {DRIVE-ID}: the id of drive (document library or list) {DRIVE-ID}:驱动器的id(文档库或列表)
  • {FILENAME}: the name of the fie to upload {FILENAME}:要上传的文件名

The "/root:" after the drive id is the important point.驱动器 ID 后面的“/root:”是重点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM