I am trying to integrate OneDrive in my app using the OneDrive iOS SDK. I managed to do most of the things I wanted but I can't seem to figure it out on how to upload an image in a folder(item) on OneDrive. Upload seems to work only if there was an existing image, the one image that I try to upload replacing it.
Here is the code that I am using to do so:
func uploadDataInFolder(folderToUploadInId: String, data: NSData) {
let uploadRequest = authenticatedOdClient?.drive().items(folderToUploadInId).contentRequest()
uploadRequest?.uploadFromData(data, completion: {
(item, error) -> Void in
if error == nil {
print("uploadSuccesfull in folder \(item.id)")
} else {
print(error)
print("upload unsuccesfull")
}
})
}
The request as you've constructed it is attempting to modify the binary contents of the folder itself (which doesn't make sense). Try:
items(folderToUploadInId).itemByPath("image.jpg").contentRequest()