wsgikit.FileUploader

class wsgikit.FileUploader

FileUploader object provides basic functionality to work with files uploaded with wsgikit.HttpRequest object

Naturally there is no need to instantiate it as far as it is instantiated automatically by HttpRequest during the HTTP request processing.

It is enough to use it as:

import wsgikit

def my_wsgi_app( environ, start_response):
        status = '200 OK'
        response_headers = [('Content-type','text/plain')]
        start_response( status, response_headers)
        
        request = wsgikit.HttpRequest( environ)
        
        if request.has_files():
                try :
                        request.FileUploader.move_all(
                                destination = '/my/cool/file/storage',
                                overwrite = True
                        )
                        my_response = 'Thank you, we saved all you pass!'
                
                except FileUploaderError as e:
                        my_response = "Oops, we can't save this! Reason: %s" %e
        
        else :
                my_response = 'There is nothing to do, sorry...'
        
        return my_response
move(self, file, destination, overwrite=False)

Moves a single uploaded file from a temporary location to the given destination. If overwrite is turned on file will be overwritten during the move, otherwise error will be raised

Parameters:
  • file – dict - file description compatible by structure with the FILES storage item from wsgikit.HttpRequest
  • destination – str - path where to move the file. If existing directory provided will save the file in that directory with the file name passed in HTTP request
  • overwrite – bool - flag, to turn on/off files overwriting
Return type:

returns new file destination on success

Raise :

FileOverwriteError, UploadedFileSaveError or MoveError

move_all(self, destination, overwrite=False, fdict=None)

Moves all the files uploaded during HTTP request to the given destination

Parameters:
  • destination – str - path where to store the files. Destination MUST be a directory, otherwise an error will be raised
  • overwrite – bool - flag, to turn on/off files overwriting
Return type:

list - new files destinations

Raise :

FileOverwriteError, UploadedFileSaveError, MoveDestinationError or MoveError

Previous topic

wsgikit.HttpRequest

Next topic

wsgikit.PrettyDict

This Page