【发布时间】:2014-03-21 07:55:57
【问题描述】:
我正在从我的 Django UI 上传一个 .rpm 文件。我能够在所需位置成功上传文件..
问题: 上传后文件大小增加,因此我在尝试提取 .rpm 文件时收到错误 --“error reading header from package” /p>
以下是我用来上传文件的函数:
// RPM_DIR = some DIR path where I am saveing the file"
def save_temporarily(file, name):
with open(os.path.join(RPM_DIR,str(name)),"wb+") as destination:
for chunk in file.chunks():
destination.write(chunk)
destination.closed
f.seek(0)
return os.path.join(RPM_DIR,str(name))
ls -ltr的输出
-rw-r--r-- 1 root root 3748319 Feb 20 new_file.rpm(用于新上传的文件)
-rw-r--r-- 1 root root 3735417 Feb 20 xyz.rpm(用于原始文件)
尺寸变大了……
请建议如何摆脱这个问题... 特别是如果可能的话,我正在寻找以下解决方案
- 我们能否介绍一下如何从文件中删除多余的字节并将其提取出来。
- 有没有办法在 python 中上传文件而无需打开并保存到指定位置。
- 为什么额外的字节会附加到文件中。
编辑
我还尝试将写入功能更改为
output_file_path = "/u001/Test/"+ file.name
result_file = open(output_file_path,"wb")
while True:
file_content = file.read(1024) ''' or simply file.read() '''
if not file_content:
break
result_file.write(file_content)
result_file.write(file_content)
result_file.close()
我得到了相同的输出没有变化...我实际上是在保存 .rpm 文件后运行以下命令(请参阅details):
rpm2cpio '+str(patch_path)+' | cpio -idm
并得到以下错误:
<open file 'rpm2cpio /u001/Test/php-5.1.4-1.esp1.x86_64.rpm | cpio -idm ', mode 'r' at 0x7f6334239030>
error: rpm2cpio: headerRead failed: region trailer: BAD, tag 491913216 type 508690432 offset -525467648 count 542113792
error reading header from package
cpio: premature end of archive
PS:这可能有助于更多地了解正在发生的事情
谢谢,
【问题讨论】:
标签: python django python-2.7 file-upload rpm