<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _upload_media(self,directory,files=None,resize_request=None):
 """Uploads media file to FLICKR, returns True if uploaded successfully, Will replace if already uploaded, If megapixels > 0, will scale photos before upload If no filename given, will go through all files in DB"""

        # Connect if we aren't already
        if not self._connectToFlickr():
            logger.error("%s - Couldn't connect to flickr")
            return False

        _tags=self._load_tags(directory)
        _megapixels=self._load_megapixels(directory)


        # If no files given, use files from DB in dir
        if not files:
            db=self._loadDB(directory)
            files=db.keys()

        #If only one file given, make it a list
        if isinstance(files,basestring):
            files=[files]

        files.sort()

        for filename in files:
            #FIXME: If this fails, should send a list
            # to Upload() about which files DID make it,
            # so we don't have to upload it again!

            status,replaced=self._upload_or_replace_flickr(directory,filename, \
                    _tags, _megapixels,resize_request)
            if not status:
                return False
            # If uploaded OK, update photo properties, tags
            # already taken care of - only update if
            # this is a new photo (eg, if it was replaced
            # then we don't need to do this
            if not replaced:
                self._update_config_location(directory,filename)
                self._update_config_sets(directory,filename)

        return True