@@ -191,6 +191,7 @@ class Importer:
191191 owner : str
192192 import_type : str = 'default'
193193 BATCH_SIZE : int = 100
194+ IMPORT_CACHE : str = "import_cache/"
194195
195196 # pylint: disable=too-many-arguments
196197 def __init__ (self , task_id , path , username , owner_type , owner , import_type = 'default' ):
@@ -229,17 +230,19 @@ def run(self): # pylint: disable=too-many-locals
229230 shutil .copyfileobj (import_file .raw , temp )
230231 self .path = file_url
231232 else :
233+ if not key .startswith (self .IMPORT_CACHE ):
234+ key = self .IMPORT_CACHE + self .path
232235 upload_service = get_export_service ()
233- if upload_service .exists (self . path ): # already uploaded by the view
234- self .path = upload_service . url_for ( self . path )
236+ if upload_service .exists (key ): # already uploaded by the view
237+ self .path = key
235238 else :
236239 with requests .get (self .path , stream = True ) as import_file :
237240 if not import_file .ok :
238241 raise ImportError (f"Failed to GET { self .path } , responded with { import_file .status_code } " )
239242 upload_service .upload (key , import_file .raw ,
240243 metadata = {'ContentType' : 'application/octet-stream' },
241244 headers = {'content-type' : 'application/octet-stream' })
242- self .path = upload_service . url_for ( key )
245+ self .path = key
243246
244247 resources = {}
245248 dependencies = []
@@ -271,8 +274,11 @@ def run(self): # pylint: disable=too-many-locals
271274 def prepare_resources (self , path , resource_types , dependencies , visited_dependencies , resources ):
272275 # pylint: disable=too-many-locals
273276 with open (path , 'rb' ) if path .startswith ('/' ) else tempfile .NamedTemporaryFile () as temp :
277+ request_path = path
274278 if not path .startswith ('/' ): # not local file
275- remote_file = requests .get (path , stream = True )
279+ if path .startswith (self .IMPORT_CACHE ):
280+ request_path = get_export_service ().url_for (path )
281+ remote_file = requests .get (request_path , stream = True )
276282 ImporterUtils .fetch_to_file (remote_file , temp )
277283
278284 is_zipped , is_tarred = ImporterUtils .is_zipped_or_tarred (temp )
@@ -559,9 +565,12 @@ def run(self):
559565 try :
560566 with open (self .path , 'rb' ) if self .path .startswith ('/' ) else tempfile .NamedTemporaryFile () as temp :
561567 if not self .path .startswith ('/' ): # not local file
562- remote_file = requests .get (self .path , stream = True )
568+ request_path = self .path
569+ if self .path .startswith (Importer .IMPORT_CACHE ):
570+ request_path = get_export_service ().url_for (self .path )
571+ remote_file = requests .get (request_path , stream = True )
563572 if not remote_file .ok :
564- raise ImportError (f"Failed to GET { self . path } , responded with { remote_file .status_code } " )
573+ raise ImportError (f"Failed to GET { request_path } , responded with { remote_file .status_code } " )
565574 ImporterUtils .fetch_to_file (remote_file , temp )
566575
567576 is_zipped , is_tarred = ImporterUtils .is_zipped_or_tarred (temp )
0 commit comments