ios - 如何在IOS中将视频文件转换为Base64字符串?
问题描述
我想将本地资源文件夹视频文件(12345.mp4)转换为 base64 编码字符串,然后从 API 发送到服务器端,但网络团队告诉无效的 base64 编码字符串。这个对吗?
这是我的代码:
NSString *base64String = @"";
NSError *error;
NSData *videoData;
NSString *strVideoPath = [[NSBundle mainBundle] pathForResource:@"12345" ofType:@"mp4"];
videoData = [[NSData alloc]initWithContentsOfFile:strVideoPath options:NSDataReadingMappedIfSafe error:&error];
base64String = [videoData base64EncodedStringWithOptions:0];
解决方案
在swift版本中,您可以像这样转换视频
*let tempURL = info[UIImagePickerController.InfoKey.mediaURL]
let data = NSData(contentsOf: tempURL as! URL)
print("\(String(describing: data?.length))")
if data?.length ?? 0 > 0{
guard data != nil else {
return
}
let base64String = data!.base64EncodedString(options: .lineLength64Characters)
self.video = base64String
}*
推荐阅读
- python - 如何从我的有序字典创建熊猫数据框?
- python - 如何检查文本特征的特征重要性?
- c# - 手动加载后,Planner 才会出现
- iis - IIS 8 Url重写规则否定不起作用
- mysql - 如何编写返回具有最多事务计数的项目名称的查询?
- docker - Dockerfile CMD 没有通过引号传递给 /bin/sh -c 入口点
- python - 从带有分类的熊猫非均匀列中提取多个数字
- dsl - 用于复杂 JSON 对象的 karate.filterKeys() API
- c - 降级后 GCC 无法编译简单的 C 应用程序
- html - 使用R markdown,有没有办法修复可滚动(html)、kable 表的行名,类似于scroll_box 函数修复标题行?