File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -801,6 +801,44 @@ async function exportFile(data) {
801801    link . remove ( ) ; 
802802} 
803803
804+ // TODO: handled by import? if value is a valid url get file by url? 
805+ async  function  importFileFromURL ( url )  { 
806+     try  { 
807+         // Fetch the file data from the URL 
808+         const  response  =  await  fetch ( url ) ; 
809+         if  ( ! response . ok )  { 
810+             throw  new  Error ( 'Network response was not ok '  +  response . statusText ) ; 
811+         } 
812+ 
813+         // Get the filename from the URL 
814+         const  urlParts  =  url . split ( '/' ) ; 
815+         const  filename  =  urlParts [ urlParts . length  -  1 ] ; 
816+ 
817+         // Convert the response data to a Blob 
818+         const  blob  =  await  response . blob ( ) ; 
819+ 
820+         // Create a File object 
821+         const  file  =  new  File ( [ blob ] ,  filename ,  {  type : blob . type  } ) ; 
822+ 
823+         // Create a custom file object with additional properties 
824+         const  fileObject  =  { 
825+             src : file , 
826+             size : file . size , 
827+             directory : '/' , 
828+             path : '/' , 
829+             pathname : '/'  +  filename , 
830+             'content-type' : file . type , 
831+             input : handle . input  ||  null , 
832+             id : await  getFileId ( file ) 
833+         } ; 
834+ 
835+         return  fileObject ; 
836+     }  catch  ( error )  { 
837+         console . error ( 'Error importing file from URL:' ,  error ) ; 
838+         throw  error ; 
839+     } 
840+ } 
841+ 
804842async  function  fileRenderAction ( action )  { 
805843    const  element  =  action . element 
806844
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments