api.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:duckpond 作者: alexmilowski 项目源码 文件源码
def content_item_resource_upload(id,property):
   #print(request.headers['Content-Type'])
   #print(request.files)
   file = request.files['file']
   #print(file.filename)
   #print(file.content_type)
   #print(file.content_length)
   uploadContentType = file.content_type
   if file.content_type.startswith("text/") and file.content_type.find("charset=")<0:
      uploadContentType = file.content_type+"; charset=UTF-8"
   uploadDir = app.config['UPLOAD_STAGING'] if 'UPLOAD_STAGING' in app.config else 'tmp'
   os.makedirs(uploadDir,exist_ok=True)
   staged = os.path.join(uploadDir, file.filename)
   file.save(staged)
   status = 500
   responseJSON = None
   contentType = None
   with open(staged,"rb") as data:
      status,responseJSON,contentType = model.uploadContentResource(id,property,file.filename,uploadContentType,os.path.getsize(staged),data)
   os.unlink(staged)
   if status==200 or status==201:
      return Response(stream_with_context(responseJSON),status=status,content_type = contentType)
   else:
      return Response(status=status)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号