Commit e56b8050 authored by Jerome Mariette's avatar Jerome Mariette
Browse files

fix a bug with uploading small file

parent be3007ed
......@@ -54,6 +54,35 @@ class UploadFieldStorage(cgi.FieldStorage):
jflowconf = JFlowConfigReader()
return jflowconf.get_tmp_directory()
def get_file_name(self):
self.tmpfile = None
# if this is a file object, just return the name of the file
if hasattr( self.file, 'name' ):
return self.file.name
# if not, this is a cStringIO.StringO, write it down
# and return the file name
else:
tmp_folder = self.get_tmp_directory()
if not os.path.exists( tmp_folder ):
try : os.mkdir(tmp_folder)
except : pass
fh = open(os.path.join(tmp_folder, self.filename), "w+")
fh_name = fh.name
fh.write(self.file.getvalue())
fh.close()
return fh_name
def __del__(self):
try:
self.file.close()
except AttributeError:
pass
try:
tmp_folder = self.get_tmp_directory()
os.remove(os.path.join(tmp_folder, self.filename))
except:
pass
def make_file(self, binary=None):
tmp_folder = self.get_tmp_directory()
if not os.path.exists( tmp_folder ):
......@@ -339,16 +368,15 @@ class JFlowServer (object):
currentFile = formFields[current]
fileDir = os.path.join(self.jflow_config_reader.get_tmp_directory(), formFields.getvalue("uniq_directory"))
os.mkdir(fileDir)
if isinstance(currentFile, list):
for cfile in currentFile:
os.link(
cfile.file.name,
cfile.get_file_name(),
os.path.join(fileDir, cfile.filename.encode('ascii','ignore'))
)
else:
os.link(
currentFile.file.name,
currentFile.get_file_name(),
os.path.join(fileDir, currentFile.filename.encode('ascii','ignore'))
)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment