uris.append(StorageURI(media_file, 'http', url, None)) # An optional streaming RTMP URI rtmp_server_uri = self._data.get('rtmp_server_uri', None) if rtmp_server_uri: uris.append(StorageURI(media_file, 'rtmp', media_file.unique_id, rtmp_server_uri)) # Remotely *download* accessible URL url = url_for(controller='/media', action='serve', id=media_file.id, slug=media_file.media.slug, container=media_file.container, qualified=True, download=1) uris.append(StorageURI(media_file, 'download', url, None)) # Internal file URI that will be used by MediaController.serve path = urlunsplit(('file', '', self._get_path(media_file.unique_id), '', '')) uris.append(StorageURI(media_file, 'file', path, None)) return uris def _get_path(self, unique_id): """Return the local file path for the given unique ID. This method is exclusive to this engine. """ basepath = self._data.get('path', None) if not basepath: basepath = config['media_dir'] return os.path.join(basepath, unique_id) FileStorageEngine.register(LocalFileStorage)
# Try to download the file. Increase the number of retries, or the # timeout duration, if the server is particularly slow. # eg: Akamai usually takes 3-15 seconds to make an uploaded file # available over HTTP. for i in xrange(max_tries): try: temp_file = urlopen(file_url) dl_hash = sha1(temp_file.read()).hexdigest() temp_file.close() except HTTPError, http_err: # Don't raise the exception now, wait until all attempts fail time.sleep(3) else: # If the downloaded file matches, success! Otherwise, we can # be pretty sure that it got corrupted during FTP transfer. if orig_hash == dl_hash: return True else: msg = _('The file transferred to your FTP server is '\ 'corrupted. Please try again.') raise FTPUploadError(msg, None, None) # Raise the exception from the last download attempt msg = _('Could not download the file from your FTP server: %s')\ % http_err.message raise FTPUploadError(msg, None, None) FileStorageEngine.register(FTPStorage)
orig_hash = sha1(file.read()).hexdigest() # Try to download the file. Increase the number of retries, or the # timeout duration, if the server is particularly slow. # eg: Akamai usually takes 3-15 seconds to make an uploaded file # available over HTTP. for i in xrange(max_tries): try: temp_file = urlopen(file_url) dl_hash = sha1(temp_file.read()).hexdigest() temp_file.close() except HTTPError, http_err: # Don't raise the exception now, wait until all attempts fail time.sleep(3) else: # If the downloaded file matches, success! Otherwise, we can # be pretty sure that it got corrupted during FTP transfer. if orig_hash == dl_hash: return True else: msg = _('The file transferred to your FTP server is '\ 'corrupted. Please try again.') raise FTPUploadError(msg, None, None) # Raise the exception from the last download attempt msg = _('Could not download the file from your FTP server: %s')\ % http_err.message raise FTPUploadError(msg, None, None) FileStorageEngine.register(FTPStorage)
orig_hash = sha1(file.read()).hexdigest() # Try to download the file. Increase the number of retries, or the # timeout duration, if the server is particularly slow. # eg: Akamai usually takes 3-15 seconds to make an uploaded file # available over HTTP. for i in xrange(max_tries): try: temp_file = urlopen(file_url) dl_hash = sha1(temp_file.read()).hexdigest() temp_file.close() except HTTPError, http_err: # Don't raise the exception now, wait until all attempts fail time.sleep(3) else: # If the downloaded file matches, success! Otherwise, we can # be pretty sure that it got corrupted during FTP transfer. if orig_hash == dl_hash: return True else: msg = _('The file transferred to your FTP server is '\ 'corrupted. Please try again.') raise SwiftUploadError(msg, None, None) # Raise the exception from the last download attempt msg = _('Could not download the file from your FTP server: %s')\ % http_err.message raise SwiftUploadError(msg, None, None) FileStorageEngine.register(SwiftStorage)