【发布时间】:2013-03-18 22:43:16
【问题描述】:
我正在努力寻找一些有用的东西来自动将照片从照片库上传到我的服务器端。 在我的 iphone 应用程序中,我想在用户拍摄新照片时自动将照片上传到服务器。 facebook、Dropbox 和 google plus 应用的做法。
任何帮助。
【问题讨论】:
标签: iphone ios objective-c camera
我正在努力寻找一些有用的东西来自动将照片从照片库上传到我的服务器端。 在我的 iphone 应用程序中,我想在用户拍摄新照片时自动将照片上传到服务器。 facebook、Dropbox 和 google plus 应用的做法。
任何帮助。
【问题讨论】:
标签: iphone ios objective-c camera
主要是一个 3 步流程:
1) 获取照片。将其存储到文档目录。苹果在这里描述得很好:PhotoPicker
2) 从文档目录获取照片:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:@"Images"];
UIImage *image = [[UIImage alloc] initWithContentsOfFile:[dataPath stringByAppendingPathComponent:[NSString stringWithFormat:@"yourImage.png"]]];
3) 现在,您可以将照片上传到服务器了。该过程在这里得到了很好的描述: upload image from iphone to the server folder
【讨论】:
Documents 目录的情况下进行上传?我知道 NSURLSession 会将上传放在后台,但是您可以在不创建本地副本的情况下上传资产吗?