def post_object(global_id, container): """ Uploads an Object, must include a file with id=file_content and a header X-Password=global_id user's password :param global_id: user id :param container: container name :return: HTTP 201 if created """ password = request.headers.get('X-Password') user = StorageUser.objects(global_id=global_id, global_pwd=password).first() if user is not None: tenant_id = user.tenant_id fil = request.files.get('file_content') try: conn = swiftclient.Connection(auth_url, global_id, password, auth_version=auth_version, tenant_name=global_id, insecure=True) conn.put_object(container, fil.filename, fil.file) conn.close() # Save to Mongo obj = StorageObject(tenant_id=tenant_id, tenant_name=global_id, container_name=container, object_name=fil.filename, user=user) obj.save() return HTTPResponse(status=201) except ClientException: traceback.print_exc(sys.stderr) abort(500, "Could not upload file") except AttributeError: abort(400, "Request malformed, probably object is not sent with the file_content identifier") else: abort(401, 'Unknown user')