简体   繁体   English

Microsoft Graph Api 上传文件到 SharePoint

[英]Microsoft Graph Api upload file to SharePoint

I'm using microsoft graph api to interview with sharepoint.我正在使用 microsoft graph api 来采访 sharepoint。

  1. Upload file to sharepoint.上传文件到共享点。

    https://graph.microsoft.com/v1.0/sites/abc78c05-a77b-45bf-a1a1-51f09548b497/drive/root:/test1212123.txt:/content https://graph.microsoft.com/v1.0/sites/abc78c05-a77b-45bf-a1a1-51f09548b497/drive/root:/test1212123.txt:/content

  2. Then we can got the response.然后我们可以得到响应。

     { "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#sites('abc78c05-a77b-45bf-a1a1-51f09548b497')/drive/root/$entity", "@microsoft.graph.downloadUrl": "https://yeeofficesg.sharepoint.com/sites/GdTest/_layouts/15/download.aspx?UniqueId=b9d25e13-c915-432f-b9fb-f2d36a188d9f&Translate=false&tempauth=eyJ0eXAiOiJKV1QiLCJhbGciOiJub25lIn0..aTVxeDdWNkowcWFDK0xYOHUvZGo3K0VVSEd1dU02MFVheEFJbnBWWUJHTT0&ApiVersion=2.0", "createdDateTime": "2020-03-20T05:34:59Z", "eTag": "\\"{B9D25E13-C915-432F-B9FB-F2D36A188D9F},1\\"", "id": "016REKDTITL3JLSFOJF5B3T67S2NVBRDM7", "lastModifiedDateTime": "2020-03-20T05:34:59Z", "name": "test1212123.txt", "webUrl": "https://yeeofficesg.sharepoint.com/sites/GdTest/Shared%20Documents/test1212123.txt", "cTag": "\\"c:{B9D25E13-C915-432F-B9FB-F2D36A188D9F},1\\"", "size": 12, "createdBy": { "application": { "id": "597d48bc-05f3-4158-8acc-ae5cc7a9c6ad", "displayName": "HttpRequest Test" } }, "lastModifiedBy": { "application": { "id": "597d48bc-05f3-4158-8acc-ae5cc7a9c6ad", "displayName": "HttpRequest Test" } }, "parentReference": { "driveId": "b!BYzHq3unv0WhoVHwlUi0l_EO2rYM2NNCptmOTvJ-EqeM9aeJ-zj_TZktSrctfA1S", "driveType": "documentLibrary", "id": "016REKDTN6Y2GOVW7725BZO354PWSELRRZ", "path": "/drive/root:" }, "file": { "mimeType": "text/plain", "hashes": { "quickXorHash": "RBBCDGQwAxrUIARAFAEJSgAAAAA=" } }, "fileSystemInfo": { "createdDateTime": "2020-03-20T05:34:59Z", "lastModifiedDateTime": "2020-03-20T05:34:59Z" } }
  3. Then I want to update the customized column of this list.然后我想更新这个列表的自定义列。 https://graph.microsoft.com/v1.0/sites/abc78c05-a77b-45bf-a1a1-51f09548b497/lists/89a7f58c-38fb-4dff-992d-4ab72d7c0d52/items/80/fields https://graph.microsoft.com/v1.0/sites/abc78c05-a77b-45bf-a1a1-51f09548b497/lists/89a7f58c-38fb-4dff-992d-4ab72d7c0d52/items/80/fields

  4. step3, I needs the item id (this example is : 80) but when I upload the file, I can't got the item id directly from the response. step3,我需要物品id(这个例子是:80)但是当我上传文件时,我不能直接从响应中得到物品id。

use this api: https://graph.microsoft.com/v1.0/sites/abc78c05-a77b-45bf-a1a1-51f09548b497/lists/89a7f58c-38fb-4dff-992d-4ab72d7c0d52/items/ I can got the items list which include the item id is needed.使用这个api: https : //graph.microsoft.com/v1.0/sites/abc78c05-a77b-45bf-a1a1-51f09548b497/lists/89a7f58c-38fb-4dff-992d-4ab72d7c0d52/items/lists/需要包含项目 ID。

Finally, my question is ,when I upload file to sharepoint, how can I got the item id which is needed by update item.最后,我的问题是,当我将文件上传到 sharepoint 时,如何获得更新项目所需的项目 ID。

I ended up extracting the Item GUID from the response, ie我最终从响应中提取了项目 GUID,即

"@microsoft.graph.downloadUrl": "https://yeeofficesg.sharepoint.com/sites/GdTest/_layouts/15/download.aspx?UniqueId= b9d25e13-c915-432f-b9fb-f2d36a188d9f &Translate=false&tempauth=.... "@microsoft.graph.downloadUrl": "https://yeeofficesg.sharepoint.com/sites/GdTest/_layouts/15/download.aspx?UniqueId= b9d25e13-c915-432f-b9fb-f2d36a188d9f &Translate=...false&tempauth= .

or或者

"eTag": ""{ B9D25E13-C915-432F-B9FB-F2D36A188D9F },1"" "eTag": ""{ B9D25E13-C915-432F-B9FB-F2D36A188D9F },1""

or或者

"cTag": ""c:{ B9D25E13-C915-432F-B9FB-F2D36A188D9F },1"" "cTag": ""c:{ B9D25E13-C915-432F-B9FB-F2D36A188D9F },1""

And then use that in the PATCH call where the item ID is required, ie https://graph.microsoft.com/v1.0/sites/abc78c05-a77b-45bf-a1a1-51f09548b497/lists/89a7f58c-38fb-4dff-992d-4ab72d7c0d52/items/**B9D25E13-C915-432F-B9FB-F2D36A188D9F**/fields然后在需要项目 ID 的 PATCH 调用中使用它,即https://graph.microsoft.com/v1.0/sites/abc78c05-a77b-45bf-a1a1-51f09548b497/lists/89a7f58c-38fb-4dff- 992d-4ab72d7c0d52/items/**B9D25E13-C915-432F-B9FB-F2D36A188D9F**/fields

Might be a more elegant way to solve the problem, however this worked for me可能是解决问题的更优雅的方法,但这对我有用

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

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