gpt4 book ai didi

ios - 如何从 ALAsset Url 获取视频 url 以在服务器上上传视频?

转载 作者:行者123 更新时间:2023-11-29 12:53:08 24 4
gpt4 key购买 nike

当使用 ELCImagePickerController 选择视频时,我得到 assets-library://asset/asset.mp4?id=F0D95698-C982-4723-8959-502CE595E3D1&ext=mp4 url 。现在,我必须检索视频名称和媒体 url,以便使用 asiDataFormRequest 将此视频上传到服务器。

当我使用 ImagePickerViewController 选择视频时,视频上传工作正常。现在我必须选择多个视频,所以我使用 ELCImagePickerController。但它给出了下面给出的视频 url。assets-library://asset/asset.mp4?id=F0D95698-C982-4723-8959-502CE595E3D1&ext=mp4

我如何将此 url 转换为 MEdia Url 类型格式。我的主要目的是使用 asihttpdatafromrequest 上传此视频并获取此大小、名称。

最佳答案

@KDRocks。此代码成功运行以获取具有完整路径的名称。

-(NSString*) videoAssetURLToTempFile:(NSURL*)url
{
NSString * surl = [url absoluteString];
NSString * ext = [surl substringFromIndex:[surl rangeOfString:@"ext="].location + 4];
NSTimeInterval ti = [[NSDate date]timeIntervalSinceReferenceDate];
NSString * filename = [NSString stringWithFormat: @"%f.%@",ti,ext];
NSString * tmpfile = [NSTemporaryDirectory() stringByAppendingPathComponent:filename];

ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
{
ALAssetRepresentation * rep = [myasset defaultRepresentation];
NSUInteger size = [rep size];
const int bufferSize = 8192;
NSLog(@"Writing to %@",tmpfile);
FILE* f = fopen([tmpfile cStringUsingEncoding:1], "wb+");
if (f == NULL)
{
NSLog(@"Can not create tmp file.");
return;
}
Byte * buffer = (Byte*)malloc(bufferSize);
int read = 0, offset = 0, written = 0;
NSError* err;
if (size != 0) {
do {
read = [rep getBytes:buffer
fromOffset:offset
length:bufferSize
error:&err];
written = fwrite(buffer, sizeof(char), read, f);
offset += read;
} while (read != 0);
}
fclose(f);
};
ALAssetsLibraryAccessFailureBlock failureblock = ^(NSError *myerror)
{
NSLog(@"Can not get asset - %@",[myerror localizedDescription]);

};
if(url)
{
ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
[assetslibrary assetForURL:url
resultBlock:resultblock
failureBlock:failureblock];
}
return tmpfile;
}

关于ios - 如何从 ALAsset Url 获取视频 url 以在服务器上上传视频?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21928108/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com