简体   繁体   中英

Uploading file to folder other than default OneDrive REST

So I'm PUTing a file onto one drive, my URI looks like https://apis.live.net/v5.0/me/skydrive/files/?access_token=12345

however, if I try and change the folder to, say, Documents:

https://apis.live.net/v5.0/me/skydrive/files/Documents?access_token=12345

or

https://apis.live.net/v5.0/me/skydrive/Documents/files?access_token=12345

I'll get a HTTP 400 (bad request error).

One "workaround" could be to query the top level directory of the onedrive, done by reading the JSON response from the first URI about, and then suck out the upload_location for a desired folder, however I feel this is a bit long winded. From the Upload a File section in https://msdn.microsoft.com/en-us/library/dn659726.aspx I got the impression I should be able to specify a friendly folder path.

I'm positive it's a really simple answer, but I've wasted long enough on it and hopefully this will serve as a resource for those having the same issue (haven't been able to find elsewhere except for an unanswered question here http://answers.microsoft.com/en-us/onedrive/forum/sdfiles-sdupload/how-to-upload-a-file-to-a-specific-folder-created/0d57e43c-a3ec-42fc-b3b7-f15a17b2836f )

Thanks

Based on your examples I think you just need to change Documents -> my_documents and then the scenario will work like you'd want. Here is the relative excerpt from the documentation .

Use friendly names to access certain OneDrive folders To access certain OneDrive folders, you can use friendly names instead of folder IDs. Use the following friendly names to access these corresponding folders in the OneDrive UI:

  • USER_ID/skydrive/camera_roll represents the OneDrive camera roll folder.
  • USER_ID/skydrive/my_documents represents the Documents folder.
  • USER_ID/skydrive/my_photos represents the Pictures folder.
  • USER_ID/skydrive/public_documents represents the Public folder.

In each case, replace USER_ID with either me for the signed-in user or a user ID for any other consenting user. For example, to read the Documents folder's properties, use a REST API call to the folder's ID, like this.

 GET https://apis.live.net/v5.0/folder.a6b2a7e8f2515e5e.A6B2A7E8F2515E5E!110?access_token=ACCESS_TOKEN

请尝试以下链接中列出的API: https : //dev.onedrive.com/README.htm#这些对我来说很好用。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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