File tree Expand file tree Collapse file tree 1 file changed +8
-11
lines changed
Expand file tree Collapse file tree 1 file changed +8
-11
lines changed Original file line number Diff line number Diff line change 4949from .usermanagement import user_login_required , login_required_if_no_ano
5050from .string_helper import strip_whitespaces
5151
52- import tempfile
52+ import io
5353import requests
5454from werkzeug .datastructures import FileStorage
5555
@@ -566,23 +566,20 @@ def do_upload_url(url: str) -> FileStorage:
566566 filename_sanitized = "" .join (c for c in url_end if c .isalnum () or c in "._-" ) # sanitize filename
567567 filename = filename_sanitized if len (filename_sanitized ) > 0 else "uploaded_file"
568568
569- with tempfile .NamedTemporaryFile (delete = False ) as tmp :
570- for chunk in r .iter_content ():
571- tmp .write (chunk )
572- tmp .flush ()
573- tmp_name = tmp .name
569+ file_buffer = io .BytesIO ()
570+ for chunk in r .iter_content ():
571+ file_buffer .write (chunk )
572+ file_buffer .seek (0 )
573+
574+ return do_upload_file_list ([FileStorage (file_buffer , filename = filename )])
575+
574576
575577 except Exception as e :
576578 log .error_or_exception ("File download error: {}" .format (e ))
577579 flash (_ ("Oops! Download failed: %(error)s." , error = e .orig if hasattr (e , "orig" ) else e ),
578580 category = "error" )
579581 return make_response (jsonify (location = url_for ("web.index" )))
580582
581- with open (tmp_name , 'rb' ) as f :
582- file_storage = FileStorage (f , filename = filename )
583- resp = do_upload_file_list ([file_storage ])
584-
585- return resp
586583
587584def do_upload_file_list (file_list : list [FileStorage ]):
588585 for requested_file in file_list :
You can’t perform that action at this time.
0 commit comments