从二进制数据获取文件路径 [英] Get File path from binary data

查看:167
本文介绍了从二进制数据获取文件路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有可能从二进制数据获取文件的路径?



我只有读取文件的二进制数据,但没有文件的信息路径。



二进制数据是否有路径信息?如果是的话我怎样才能得到它。

我需要使用python xlrd lib来读取xlsx文件,这需要文件路径
,但是我只有二进制文件数据。



任何人都可以点亮它吗?

解决方案

(b
$ b $ pre $ def $ read_file(self,cr,uid,ids,context = None):
如果不是上下文:context = {}
rec = self.browse(cr,uid,ids [0],context)
file_path = tempfile.gettempdir()+'/ file.xlsx'
data = rec.file
f = open(file_path,'wb')
f.write(data.decode('base64'))
f.close()
wb = xlrd.open_workbook(file_path)
....

然后你可以做你的过程。


Is it possible to get the path of a file from binary data?

I have only binary data which came from reading the file, but have no information of file path.

Does the binary data have the information of path? if yes then How can I get it.

I need to read xlsx file using python xlrd lib, which requires the file path, but i only have binary data.

Can anyone shed light on it?

解决方案

I have Done this before like,

def read_file(self, cr, uid, ids, context=None):
    if not context: context = {}
    rec = self.browse(cr, uid, ids[0], context)
    file_path = tempfile.gettempdir()+'/file.xlsx'
    data = rec.file
    f = open(file_path,'wb')
    f.write(data.decode('base64'))
    f.close()
    wb = xlrd.open_workbook(file_path)
    ....

Then you can do your process.

这篇关于从二进制数据获取文件路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆