我需要它,因为我正在使用AJAX传输文件,因此我得到了一个base64编码的字符串格式的图像文件。我想把它很好地转换成FileStorage对象,这样我就可以很好地使用flask-uploads库了。你知道我该怎么做吗?谢谢!
发布于 2011-09-15 18:31:43
def open_file(file_name):
"""
opens file in samples, and return base64 encoded streams.
feel free to use this code if it is helpful.
"""
from backend import backend
sample_dir = backend.config["samples_dir"]
file = open(os.path.join(sample_dir, file_name), 'r')
stream = file.read()
encoded_stream = base64.b64encode(stream)
return encoded_stream发布于 2011-09-08 04:38:12
看一下pickle模块,特别是pickle.load函数。此模块帮助将对象转换为字节流或从字节流转换。
您可能还需要使用binascii转换字符串。
https://stackoverflow.com/questions/7339833
复制相似问题