31 from ec2.settings
import UPLOAD_IMAGES_PATH
36 QUERY_IMAGE_NAME =
'image_name'
39 logging.basicConfig(stream=sys.stdout)
40 logging.basicConfig(stream=sys.stderr)
52 def _environ_to_parameters(environ):
53 query_string = environ[
'QUERY_STRING']
55 query_string_params = urlparse.parse_qs(query_string)
56 if len(query_string_params) != 1:
60 parameters[
'image_name'] = query_string_params[
'image_name'][0]
64 print 15 *
'=',
'PARAMETERS', 15 *
'='
65 for u, v
in parameters.iteritems():
73 print 15 *
'=',
'EC2-CM-UPLOAD', 15 *
'='
76 parameters = _environ_to_parameters(environ)
78 image_name = parameters[QUERY_IMAGE_NAME]
79 file_path = os.path.join(UPLOAD_IMAGES_PATH, image_name)
81 image_file = open(file_path,
'r')
82 start_response('200 OK', [])
83 if 'wsgi.file_wrapper' in environ:
84 return environ[
'wsgi.file_wrapper'](image_file, BLOCK_SIZE)
86 return iter(
lambda: image_file.read(BLOCK_SIZE),
'')
88 except Exception, error:
90 start_response(
'500 Internal Server Error', [(
'Content-Type',
'text/plain')])
96 response = traceback.format_exc()
99 response =
'500 Internal Server Error'