File tree Expand file tree Collapse file tree 3 files changed +17
-7
lines changed Expand file tree Collapse file tree 3 files changed +17
-7
lines changed Original file line number Diff line number Diff line change @@ -16,11 +16,14 @@ For better usage, `FILES_URL` enviroment should be set.
1616If not, an ` url `  argument for the files server URL should be used.
1717
1818``` python 
19- from  files_ms_client.client import  download, upload
19+ from  files_ms_client.client import  download, upload, delete 
2020
2121#  Upload a file
2222response =  upload(' ../path/to/file.txt' 
2323
2424#  Download a file
2525download(' file_name' ' ../path/to/new_file.txt' 
26+ 
27+ #  Delete a file
28+ delete(' file_name' 
2629``` 
Original file line number Diff line number Diff line change 11from  os  import  getenv 
2- from  requests  import   post ,  get 
2+ import  requests  as   req 
33import  json 
44from  mimetypes  import  guess_type 
55
99# Upload a file to the server 
1010def  upload (file : str , url : str  =  files_url ):
1111    files  =  {file_key : (file , open (file , 'rb' ), guess_type (file )[0 ])}
12-     r  =  post (f'{ url }  , files = files )
12+     r  =  req . post (f'{ url }  , files = files )
1313    return  r .json ()[file_key ]
1414
1515# Download a file from the server 
1616def  download (file : str , path : str , url : str  =  files_url ):
17-     r  =  get (f'{ url } { file }  )
17+     r  =  req . get (f'{ url } { file }  )
1818    open (path , 'wb' ).write (r .content )
19+ 
20+ # Delete a file from the server 
21+ def  delete (file : str , url : str  =  files_url ):
22+     r  =  req .delete (f'{ url } { file }  )
23+     return  r .json ()
Original file line number Diff line number Diff line change 33sys .path .append (modules_dir )
44
55# Usage example 
6- from  client  import  download , upload 
6+ from  client  import  download , upload ,  delete 
77url  =  'http://localhost:3000' 
88r  =  upload ('../temp/test.jpg' , url )
9+ print (r )
910download (r ['name' ], '../temp/result.jpg' , url )
10- 
11- print (r )
11+ print (
12+     delete (r ['name' ], url )
13+ )
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments