Downloading a file from Dropbox for documents directory deletes all my files

懵懂的女人 提交于 2019-12-25 18:27:09

问题


My app shows dropbox files, and the documents directory. when viewing dropbox files i can press a button that shows a list of all my document folders, and subdirectories in those folders so they can chose the folder they want to put that file in the documents. when doing this i used dropbox's objective c API they say to use in the documentation to download a file into a path on the system.

NSString *DocumentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];

for (NSIndexPath *indexPath in [dropboxFilesTable indexPathsForSelectedRows]) {

    DBMetadata *fileMetadata = [[dropboxFolderMetadata contents] objectAtIndex:indexPath.row];

    [[self restClient] loadFile:fileMetadata.path intoPath:DocumentsPath];
}

the delegate for the dropbox says it is successfully put inside, but when i went back in, every folder and downloaded file has been deleted and that file is still not in the folder. i thought it would need the final path like "path to documents"/"filename", but then dropbox gives a error for that. Anyone know why its deleting all my files and not putting it in my documents?


回答1:


The intoPath parameter needs to be a full filename path, not a directory. You need to update the last line to something like:

NSString *filename = [fileMetadata.path lastPathComponent];
NSString *destPath = [DocumentsPath stringByAppendingPathComponent:filename];
[[self restClient] loadFile:fileMetadata.path intoPath:destPath];

Also make sure that you are only doing this will files and not folders.



来源:https://stackoverflow.com/questions/13325616/downloading-a-file-from-dropbox-for-documents-directory-deletes-all-my-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!