How to upload image, which is not saved on the device to the dropbox account?(IOS)

天大地大妈咪最大 提交于 2019-12-05 03:44:21

问题


Dropbox restClient saves only files. So i want to save the image in local folder first and then to upload it, as a result it saves file, but it is corrupted.

NSString *localPath = [[NSBundle mainBundle] pathForResource:@"Info" ofType:@"plist"];
NSString *jpegFilePath = [NSString stringWithFormat:@"%@/test.jpeg",localPath];
NSData *data2 = [NSData dataWithData:UIImageJPEGRepresentation(image, 1.0f)];
[data2 writeToFile:jpegFilePath atomically:YES];

NSString *filename = @"test.jpeg";

NSString *destDir = @"/";
[[self restClient] uploadFile:filename toPath:destDir
                withParentRev:nil fromPath:localPath];

I am an idiot, solved

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *path = [[paths objectAtIndex:0] stringByAppendingString:@"test.jpg"];

NSData * data = [NSData dataWithData:UIImageJPEGRepresentation(image, 1.0f)];
[data writeToFile:path atomically:YES];
[self.restClient uploadFile:@"test.jpg" toPath:@"/" withParentRev:nil fromPath:path];

回答1:


you will have to call DBRestClient methods from the main thread or a thread that has a run loop. Otherwise the delegate methods will not be called.

what you will have to do is first alloc init yoir DBRestClient object then make it's delegate self and then you can easily upload your file.below is an example

NSString *destDir = @"/";
restClient = [[DBRestClient alloc] initWithSession:[DBSession sharedSession]];
restClient.delegate = self;

[restClient uploadFile:yourfilename toPath:destDir withParentRev:nil fromPath:sourcepath];

Happy Coding!!!!!!




回答2:


You can't save into the bundle. You should use documents or cache folder:

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


来源:https://stackoverflow.com/questions/8985084/how-to-upload-image-which-is-not-saved-on-the-device-to-the-dropbox-accountio

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