我正在使用DropboxSDK(核心API)。我使用此功能上传文件:
- (void)uploadFile {
[[self restClient] loadMetadata:@"/MyFolder"];
}
- (void)restClient:(DBRestClient *)client loadedMetadata:(DBMetadata *)metadata {
if (metadata.isDirectory) {
if (metadata.contents.count == 0) {
NSString *filename = @"File.txt";
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [documentPaths objectAtIndex:0];
NSString *databasePath = [documentsDir stringByAppendingPathComponent:filename];
NSString *destDir = @"/MyFolder";
[[self restClient] uploadFile:filename toPath:destDir withParentRev:nil fromPath:databasePath];
} else {
for (DBMetadata *file in metadata.contents) {
[self overwriteFile:metadata];
}
}
}
}
我尝试使用此功能覆盖文件“File.txt”,但它不起作用。
- (void)overwriteFile:(DBMetadata*)meta {
NSString *filename = @"File.txt";
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [documentPaths objectAtIndex:0];
NSString *databasePath = [documentsDir stringByAppendingPathComponent:filename];
[[self restClient] uploadFile:filename toPath:meta.path withParentRev:meta.rev fromPath:databasePath];
}
致电此委托:
- (void)restClient:(DBRestClient *)client uploadedFile:(NSString *)destPath from:(NSString *)srcPath metadata:(DBMetadata *)metadata {
NSLog(@"File uploaded successfully to path: %@", metadata.path);
}
我在日志中显示: 文件已成功上传到路径:/myfolder/File.txt。然后我去了Dropbox,我看到,我的文件的日期没有改变。
我做错了什么?你能救我吗?
答案 0 :(得分:0)
请注意,uploadFile
会上传到路径 filename
中名为toPath
的文件。在我看来,你可能正试图上传到像/MyFolder/File.txt/File.txt
这样的东西。确保toPath
是您要将文件File.txt
写入的文件夹。