本文整理汇总了Python中django.core.files.uploadedfile.UploadedFile.multiple_chunks方法的典型用法代码示例。如果您正苦于以下问题:Python UploadedFile.multiple_chunks方法的具体用法?Python UploadedFile.multiple_chunks怎么用?Python UploadedFile.multiple_chunks使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.core.files.uploadedfile.UploadedFile
的用法示例。
在下文中一共展示了UploadedFile.multiple_chunks方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: accept_uploaded_photo
# 需要导入模块: from django.core.files.uploadedfile import UploadedFile [as 别名]
# 或者: from django.core.files.uploadedfile.UploadedFile import multiple_chunks [as 别名]
def accept_uploaded_photo(request, album_id):
"""
Main Multiuploader module.
Parses data from jQuery plugin and makes database changes.
"""
if request.method == 'POST':
logid = random.randint(0,1000)
log.info('[%s] received POST to main multiuploader view' % logid)
if request.FILES == None:
return HttpResponseBadRequest('Must have files attached!')
#getting file data for farther manipulations
file = request.FILES[u'files[]']
wrapped_file = UploadedFile(file)
filename = wrapped_file.name
file_size = wrapped_file.file.size
log.info ('[%s] Got file: "%s"' % (logid, str(filename)))
# Write out file to disk as a temp file
randnumber = logid # use the random number here too
temp_filename = '%stmp%s_%s' % (settings.TEMP_DIRECTORY,randnumber, filename)
log.info('[%s] Writing out to: %s' % (logid, temp_filename))
destination = open(temp_filename, 'wb+')
if wrapped_file.multiple_chunks():
for chunk in wrapped_file.chunks():
destination.write(chunk)
else:
destination.write(wrapped_file.read())
destination.close()
# Dump out EXIF Tags
# im = Image.open(temp_filename)
# if hasattr( im, '_getexif' ):
# exifinfo = im._getexif()
# if exifinfo:
# for tag, value in exifinfo.items():
# decoded = ExifTags.TAGS.get(tag, tag)
# log.info('Found tag: %s, value: %s' % (decoded,value))
orientation = None
date_taken = None
# Make full size and thumbsize
try:
im = Image.open(temp_filename)
except IOError:
log.info('[%s] Error opening file %s: %s %s' % (logid, temp_filename, e.errno, e))
return HttpResponseBadRequest('Could not read file')
if hasattr( im, '_getexif' ):
exifinfo = im._getexif()
if exifinfo:
for tag, value in exifinfo.items():
decoded = ExifTags.TAGS.get(tag, tag)
# if decoded != 'MakerNote':
# if decoded != 'UserComment':
# log.info('Found tag: %s, value: %s' % (decoded,value))
if decoded == 'Orientation':
orientation = value
log.info('[%s] Found tag: %s, value: %s' % (logid,decoded,value))
elif decoded == 'DateTime':
date_taken = datetime.strptime(value, "%Y:%m:%d %H:%M:%S")
log.info('[%s] Found tag: %s, value: %s, date_taken=%s' % (logid,decoded,value,date_taken))
# We rotate regarding to the EXIF orientation information
if orientation:
if orientation == 1:
# Nothing
log.info('[%s] Orientation: No rotation necessary' % logid)
pass
elif orientation == 2:
# Vertical Mirror
log.info('[%s] Orientation: Vertical flip' % logid)
im = im.transpose(Image.FLIP_LEFT_RIGHT)
elif orientation == 3:
# Rotation 180
log.info('[%s] Orientation: Rotation 180' % logid)
im = im.transpose(Image.ROTATE_180)
elif orientation == 4:
# Horizontal Mirror
log.info('[%s] Orientation: Horizontal Mirror' % logid)
im = im.transpose(Image.FLIP_TOP_BOTTOM)
elif orientation == 5:
# Horizontal Mirror + Rotation 270
log.info('[%s] Orientation: Flip top bottom, rot 270' % logid)
im = im.transpose(Image.FLIP_TOP_BOTTOM).transpose(Image.ROTATE_270)
elif orientation == 6:
# Rotation 270
log.info('[%s] Orientation: Rotate 270' % logid)
im = im.transpose(Image.ROTATE_270)
elif orientation == 7:
# Vertical Mirror + Rotation 270
log.info('[%s] Orientation: Flip left right, rotate 270' % logid)
im = im.transpose(Image.FLIP_LEFT_RIGHT).transpose(Image.ROTATE_270)
elif orientation == 8:
# Rotation 90
log.info('[%s] Orientation: Rotate 90' % logid)
im = im.transpose(Image.ROTATE_90)
#------------------
# Save the transposed image to disk
#.........这里部分代码省略.........