本文整理汇总了Python中invenio_files_rest.models.FileInstance.get方法的典型用法代码示例。如果您正苦于以下问题:Python FileInstance.get方法的具体用法?Python FileInstance.get怎么用?Python FileInstance.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类invenio_files_rest.models.FileInstance
的用法示例。
在下文中一共展示了FileInstance.get方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_fileinstance_get
# 需要导入模块: from invenio_files_rest.models import FileInstance [as 别名]
# 或者: from invenio_files_rest.models.FileInstance import get [as 别名]
def test_fileinstance_get(app, db, dummy_location):
"""Test fileinstance get."""
f = FileInstance.create()
db.session.commit()
# Get existing file.
assert FileInstance.get(f.id) is not None
# Non-existing files returns none
assert FileInstance.get(uuid.uuid4()) is None
示例2: upload_to_zenodo
# 需要导入模块: from invenio_files_rest.models import FileInstance [as 别名]
# 或者: from invenio_files_rest.models.FileInstance import get [as 别名]
def upload_to_zenodo(bucket_id, filename):
"""Upload code to zenodo."""
zenodo_server_url = current_app.config.get('ZENODO_SERVER_URL')
params = {"access_token": current_app.config.get(
'ZENODO_ACCESS_TOKEN')}
filename = filename + '.tar.gz'
r = requests.post(zenodo_server_url,
params=params, json={},
)
file_obj = ObjectVersion.get(bucket_id, filename)
file = FileInstance.get(file_obj.file_id)
bucket_url = r.json()['links']['bucket']
with open(file.uri, 'rb') as fp:
response = requests.put(
bucket_url + '/{}'.format(filename),
data=fp,
params=params,
)
return jsonify({"status": response.status_code})