【发布时间】:2011-02-16 18:37:47
【问题描述】:
我在从某个文件(例如 .mp4/.ogg/etc.)获取 URI 时遇到了一些麻烦。 问题是我需要在运行网络服务器的 python 中执行此操作。
最初,我是这样进行的:
def __parse64(self, path_file):
string_file = open(path_file, 'r').readlines()
new_string_file = ''
for line in string_file:
striped_line = line.strip()
separated_lines = striped_line.split('\n')
new_line = ''
for l in separated_lines:
new_line += l
new_string_file += new_line
self.encoded_string_file = b64.b64encode(new_string_file)
但是,如果您将结果与给定的here. 进行比较,则不会提供我需要的东西
我需要的是一种在 python 中从 FileReader 类(参见上面链接的代码)中实现函数 readAsDataURL() 的方法。
更新: @SeanVieira 给出的解决方案,返回 URI 的有效数据字段。
def __parse64(self, path_file):
file_data = open(path_file, 'rb').read(-1)
self.encoded_string_file = b64.b64encode(file_data)
现在我怎样才能用前面的字段来完成 URI? 喜欢this。
例如:data:video/mp4;base64,data
谢谢!
【问题讨论】:
标签: python uri filereader