'How to implement if file in request.files is not empty

The Logic I'm attempting to implement: if the user doesn't upload a file to a Filefield thus leaving it empty, then don't upload the file to the S3 bucket or create a link to it. Line 8/9 doesn't do what I expected cause it still uploads empty files to the bucket & creates a link to it on my ticket.

uploads = [['frontview', 'upload', '<b>Frontview: </b>'],['backview', 'upload2', '<b>Backview: </b>'], ['electricalsupply', 'upload3', '<b>Electrical Supply: </b>'], ['fullstructure', 'upload4', '<b>Full Structure: </b>'], ['controlroom', 'upload5', '<b>Control Room: </b>'], ['otherdoc', 'upload6', '<b>Other Documentation: </b>'], ['customersignoff', 'upload7', '<b>Customer Sign-Off: </b>']]
        file_upload_urls = []
        folder = str(datetime.datetime.now()).replace(' ', '') + '/' # sets folder to the current date & time while getting rid of spaces & adding forward slash for linking purposes
        for upload in uploads: #loops through uploads array
            files = request.files.getlist(upload[1])
            section_urls = []
            for file in files: #loops through uploads array more specifically each File (upload, upload2, upload3, etc)
                if file not in request.files:
                    filename = str(upload[0] + '_' + file.filename).replace(' ', '')
                    section_urls.append(current_app.config['NEVCODOCS_BASE_URL'] + folder + filename)
                    path = "ServiceRegistration/" + folder + filename
                    s3.Bucket('nevcodocs').put_object(Key=path, Body=file)
            file_upload_urls.append([upload[2], section_urls])
​
        # Installation photos are placed in an unordered list & formats links of photos for ticket submission
        for section in file_upload_urls:
            ticket_html = ticket_html + section[0] + '<ul>'
            for url in section[1]:
                ticket_html = ticket_html + '<li> <href=' + url + '">' + url + '</href></li>'
            ticket_html = ticket_html + '</ul>'

The code below is a snippet from above, but I figured I would add the entire function for context. My intended function would be: While looping through each FileField, retrieve the data of each FileField, and run a check to see if a file was uploaded in each field. If there's data, then upload that file to S3 Bucket. If the FileField is empty, loop moves on to the next FileField. I've tried if len(request.files[file]) != 0, if not request.files.get(file, None), and if not request.files[file].filename == '' to no avail as those either lead to a 400 Bad Request, omits every FileField even if a file was uploaded, or continues to upload blank files.

        for file in files: #loops through uploads array more specifically each FileField (upload, upload2, upload3, etc)
            # if not len(request.files[file]) == 0:
            if file not in files:
                filename = str(upload[0] + '_' + file.filename).replace(' ', '')
                section_urls.append(current_app.config['NEVCODOCS_BASE_URL'] + folder + filename)
                path = "ServiceRegistration/" + folder + filename
                s3.Bucket('nevcodocs').put_object(Key=path, Body=file)


Solution 1:[1]

Solution: if not file.filename == '':

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Steven Nguyen