我正在保存我的保管箱中的example.txt
文件。当我在该txt文件中添加一些文本时,我想从Dropbox中删除以前的文件并添加新文件作为相同的example.txt名称。但它没有发生。
这是上传文件代码:
NSString *text = @"Hello Word !!!!";
NSString *filename = @"working-draft.txt";
NSString *localDir = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
NSString *localPath = [localDir stringByAppendingPathComponent:filename];
[text writeToFile:localPath atomically:YES encoding:NSUTF8StringEncoding error:nil];
[self.restClient deletePath:@"/working-draft.txt"]; // Here I am deleting Previous txt file and adding new file
// Upload file to Dropbox
NSString *destDir = @"/";
[self.restClient uploadFile:filename toPath:destDir withParentRev:nil fromPath:localPath];
委托方法:
#pragma mark Delegate method for Uploading file in dropbox --------
- (void)restClient:(DBRestClient *)client uploadedFile:(NSString *)destPath
from:(NSString *)srcPath metadata:(DBMetadata *)metadata {
NSLog(@"File uploaded successfully to path: %@", metadata.path);
self.activityIndicate.hidden = YES;
}
- (void)restClient:(DBRestClient *)client uploadFileFailedWithError:(NSError *)error {
NSLog(@"File upload failed with error: %@", error);
}
在上传期间,我删除了之前的txt文件并上传了新文件。但有时首先添加名为example(2).txt
的第二个文件,并在添加之后删除之前的文件。
我该如何解决这个问题。请任何人都可以帮助我。 ?
答案 0 :(得分:0)
两件事:
deletedPath
代理(表示删除已完成)。overwrite
参数。支持overwrite
在v1 iOS SDK中并不是很好,所以我相信您需要使用uploadFile
的重载来获取params
字典,如下所示:
NSMutableDictionary *params =
[NSMutableDictionary dictionaryWithObjects:@"true"
forKey:@"overwrite"];
[self.restClient uploadFile:filename
toPath:destDir
fromPath:localPath
params:params];
答案 1 :(得分:0)
对于Swift 3。
如果要覆盖该文件:
client.files.upload(path: filePath, mode: .overwrite, autorename: false, clientModified: nil, mute: true, input: data).response(completionHandler: { (response, error) in
if let metadata = response {
aPrint("Uploaded file name: \(metadata.name)"); aPrint("Uploaded file revision: \(metadata.rev)")
completionHandler(metadata, error)
} else {
completionHandler(nil, error)
}
})
如果要删除文件:
if let client = DropboxClientsManager.authorizedClient {
client.files.delete(path: filePath).response(completionHandler: { (response, error) in
if let metadata = response {
aPrint("Uploaded file name: \(metadata.name)")
completionHandler(metadata, error)
} else {
completionHandler(nil, error)
}
})
}