cod*_*ath 4 objective-c dropbox ios alassetslibrary
在我的iOS应用程序中,我正在尝试使用Dropbox提供的"uploadFile"调用.我正在使用ALAssetsLibrary来选择以编程方式获得的特定照片/视频作为资产.我需要将该特定资产上传到Dropbox.
//ALAsset *asset is the asset i intend to upload
[self.restClient uploadFile:[asset.defaultRepresentation filename] toPath:@"/" withParentRev:nil fromPath:[asset.defaultRepresentation.url absoluteString]];
Run Code Online (Sandbox Code Playgroud)
Dropbox似乎不喜欢资产所带的路径,看起来像这样:"assets-library://asset/asset.PNG?..."
我已为应用启用了位置服务,我也可以列出所有资产.
上传调用在日志中抛出错误"[警告] DropboxSDK:文件不存在(assets-library://asset/asset.PNG?id = 5DC234C1-B27E-45E2-BE61-46E9A266C818&ext = PNG)".
将调用uploadFileFailedWithError函数并显示错误 - ("Error Domain = dropbox.com Code = 1001"操作无法完成.(dropbox.com错误1001.")
我发送uploadFile调用的方式有什么不对,尤其是"from"路径?任何帮助将不胜感激.
您只获得一个引用,而不是一个有效的文件URL,这对于外面的类是没用的AssetsLibrary.但是,您可以非常轻松地获取资产数据并将其自己保存到磁盘:
- (void)writeAsset:(ALAsset *)asset toPath:(NSString *)path
{
ALAssetRepresentation *representation = asset.defaultRepresentation;
long long size = representation.size;
NSMutableData *rawData = [[NSMutableData alloc] initWithCapacity:size];
void *buffer = [rawData mutableBytes];
[representation getBytes:buffer fromOffset:0 length:size error:nil];
NSData *assetData = [[NSData alloc] initWithBytes:buffer length:size];
[assetData writeToFile:path atomically:YES];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2298 次 |
| 最近记录: |