0

How are we uploading files inside a folder in a SharePoint/OneDrive library(Please note not at the root level of library but inside a folder in a library). The api for uploading it in root level of a library is

https://graph.microsoft.com/v1.0/sites/$($SharePointSiteid)/drives/$($LibraryId)/root/children/$filename.txt/creatUploadSession

How do I modify the api to include the folder name or Id? How to do it with a folder in library?

Ankit Kumar
  • 476
  • 1
  • 11
  • 38

1 Answers1

0

You need to use the similar HTTP call that is specified below.

https://graph.microsoft.com/v1.0/sites/{siteid}/drives/{libraryid}/root:/Shiva 1/Document.docx:/createUploadSession

Here Shiva 1 is my Folder inside my Document Library.

Here Document.docx is the document which is already present in my folder.

enter image description here

You need to provide the name of a file which is already in that folder as this API is used to upload a new version of an already existing document by using the file name.

Shiva Keshav Varma
  • 3,398
  • 2
  • 9
  • 13
  • Hi Shiva, what do you mean the file should already by present, i am uploading the files in the folder, why do that need to be already present, also I am able to do it in the library level. I followe dyour code above and it gives me Json payload is empty error ifi try to upload inside a folder – Ankit Kumar Dec 10 '20 at 17:47
  • As it is said [here](https://stackoverflow.com/questions/60402838/how-to-perform-a-resumable-upload-to-a-sharepoint-site-not-root-subfolder-usin) this API is used to create new version of an already existing file. – Shiva Keshav Varma Dec 10 '20 at 18:00
  • Please raise a feature request for this scenario in the [Microsoft Graph Feedback Forum](https://microsoftgraph.uservoice.com/forums/920506-microsoft-graph-feature-requests) so that the product team may implement it in future. – Shiva Keshav Varma Dec 10 '20 at 18:05
  • but are you sure, I am able to upload it in a document library , i just want to upload it in a folder inside document library?? – Ankit Kumar Dec 10 '20 at 18:09
  • Yes, according to the [endpoints documented](https://learn.microsoft.com/en-us/graph/api/driveitem-createuploadsession?view=graph-rest-1.0#http-request) it is not specified how to upload file in a document library's folder as the item id indicates its a file. If you give the itemid which is folderid, it is considered as uploading Folder and you will see the error message as shown in the SO Thread link which I provided above. – Shiva Keshav Varma Dec 10 '20 at 18:13
  • @AnkitKumar, you can do it by using the id of the folder, instead of the path. – Rafael Guimaraes Siqueira Mar 16 '22 at 19:35