diff --git a/openstack_dashboard/api/glance.py b/openstack_dashboard/api/glance.py index 1fe514e630..16c72a9cbc 100644 --- a/openstack_dashboard/api/glance.py +++ b/openstack_dashboard/api/glance.py @@ -461,7 +461,16 @@ def image_create(request, **kwargs): {'data': data}) else: def upload(): - return glanceclient(request).images.upload(image.id, data) + try: + return glanceclient(request).images.upload(image.id, data) + finally: + filename = str(data.file.name) + try: + os.remove(filename) + except OSError as e: + LOG.warning('Failed to remove temporary image file ' + '%(file)s (%(e)s)', + {'file': filename, 'e': e}) thread.start_new_thread(upload, ()) return Image(image)