Handle create/update of images with unknown size
It may not be possible to know in advance the total size of image data which is to be uploaded, for example if the data is being piped to stdin. To handle this we use HTTP Transfer-Encoding: chunked and do not set any image size headers. Various subtly different cases needed to be handled for both image-create and image-update, including: * input from named pipe * piped input of zero size * regular file of zero length Fix for bug 1056220. Change-Id: I0c7f0a64d883e058993b954a1c465c5b057f2bcf
This commit is contained in:
@@ -81,9 +81,20 @@ def _set_data_field(fields, args):
|
||||
if args.file:
|
||||
fields['data'] = open(args.file, 'rb')
|
||||
else:
|
||||
if msvcrt:
|
||||
msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY)
|
||||
fields['data'] = sys.stdin
|
||||
# We distinguish between cases where image data is pipelined:
|
||||
# (1) glance ... < /tmp/file or cat /tmp/file | glance ...
|
||||
# and cases where no image data is provided:
|
||||
# (2) glance ...
|
||||
if (sys.stdin.isatty() is not True):
|
||||
# Our input is from stdin, and we are part of
|
||||
# a pipeline, so data may be present. (We are of
|
||||
# type (1) above.)
|
||||
if msvcrt:
|
||||
msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY)
|
||||
fields['data'] = sys.stdin
|
||||
else:
|
||||
# We are of type (2) above, no image data supplied
|
||||
fields['data'] = None
|
||||
|
||||
|
||||
@utils.arg('id', metavar='<IMAGE_ID>', help='ID of image to describe.')
|
||||
|
||||
Reference in New Issue
Block a user