In my application I am giving the user an option to upload his data to OneDrive. I upload the sqlite file to onedrive.
(void) uploadFile
{
NSString *localDir = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
NSString *localPath = [localDir stringByAppendingPathComponent:@"Up_Date.sqlite"];
NSData *fileToUpload = [NSData dataWithContentsOfFile:localPath options:NSDataReadingUncached error:nil];
[self.liveClient uploadToPath:@"folder.37153326d9bb21f1.37153326D9BB21F1!2286" fileName:@"Up_Date.sqlite" data:fileToUpload overwrite:0 delegate:self userState:@"upload-sql"];
}
Then the user can restore his data anytime. I download the sqlite file back.
(void) downloadFile
{
[self.liveClient downloadFromPath:@"file.37153326d9bb21f1.37153326D9BB21F1!2287/content?download=true" delegate:self userState:@"download-sql"];
}
the problem is that I couldn't find anyway of uploading and downloading using the file name. I have to use the file ID. but the ID changes evrytime the file is uploaded.
This code would work the first time its run, but if the user wants to backup his data again, the id of the sqlite file on OneDrive would change preventing me from downloading it when I want to.
Is there a way to download using the file name? Am I missing something?
When you upload files to OneDrive, if there is a name conflict, the newly uploaded file stream is automatically renamed by the service, and this creates a brand new file.
I believe you want to use the overwrite=true
option to reuse the same file reference for the updated content
This should allow you to keep track of the files that you know about, and not have to constantly re-reference the file on OneDrive