[英]DropBox file upload using core api https://api-content.dropbox.com/1/files/<root>/<path>
[英]Unable to upload files (using ALAsset libraries) to dropbox using the dropbox API
在我的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]];
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];
}
@hwaxxer的解决方案非常适合小型资产。 如果您想存储任何大小的资产并避免内存消耗问题,请查看以下答案:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.