如何将未保存在设备上的图像上传到保管箱帐户?(IOS) [英] How to upload image, which is not saved on the device to the dropbox account?(IOS)

查看:116
本文介绍了如何将未保存在设备上的图像上传到保管箱帐户?(IOS)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Dropbox restClient仅保存文件。所以我想首先将图像保存在本地文件夹中,然后上传它,因此它保存文件,但它已损坏。

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];

我是白痴,已经解决了

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];


推荐答案

你必须从主线程中调用DBRestClient方法或者具有运行循环的线程。否则不会调用委托方法。

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.

你要做的是首先分配init yoir DBRestClient对象然后让它自己委托,然后你可以轻松上传你的文件.below是一个例子

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!!!!!!

这篇关于如何将未保存在设备上的图像上传到保管箱帐户?(IOS)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆