本文整理汇总了Python中mediacrush.objects.File.taskid方法的典型用法代码示例。如果您正苦于以下问题:Python File.taskid方法的具体用法?Python File.taskid怎么用?Python File.taskid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mediacrush.objects.File
的用法示例。
在下文中一共展示了File.taskid方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: upload
# 需要导入模块: from mediacrush.objects import File [as 别名]
# 或者: from mediacrush.objects.File import taskid [as 别名]
def upload(f, filename):
if not f.content_type:
f.content_type = get_mimetype(filename) or "application/octet-stream"
#if f.content_type.split("/")[0] not in ['video', 'image', 'audio']:
# return "no", 415
ignore_limit = current_app.debug or r.sismember(_k("whitelisted_ips"), get_ip())
if not ignore_limit:
rate_limit_update(file_length(f))
if rate_limit_exceeded():
return None, 420
h = get_hash(f)
identifier = to_id(h)
if "." not in filename:
ext = mimetypes.guess_extension(f.content_type)[1:] # This not very scientific, but it works
else:
ext = extension(filename)
filename = "%s.%s" % (identifier, ext)
path = tempfile.NamedTemporaryFile(suffix="." + ext).name # Fix for imagemagick's silliness
if os.path.exists(file_storage(filename)):
if File.exists(identifier):
return identifier, 409
else:
# Delete residual files from storage by creating a dummy File
dummy = File(original=filename)
dummy.delete = lambda: None # nop
delete_file(dummy)
f.seek(0) # Otherwise it'll write a 0-byte file
f.save(path)
file_object = File(hash=identifier)
file_object.compression = os.path.getsize(path)
file_object.original = filename
file_object.mimetype = f.content_type
file_object.ip = secure_ip()
result = process_file.delay(path, identifier, ignore_limit)
file_object.taskid = result.id
file_object.save()
return identifier, 200