我使用背叶编辑latex文档。背页平台有一个上传图像文件的功能,然后可以引用该文件并将其包含在latex文档中。
我能够手动将图像上传到背页平台,并从我的latex文档中成功地使用/引用它们,但是我想知道是否有一种方法可以通过API编程地进行上传。
我想我可能需要使用https://github.com/overleaf/filestore,但我不知道如何开始。
FYI:我的主要用例是使用Python,特别是Google笔记本。
发布于 2021-01-19 17:55:41
发布于 2021-03-23 20:35:22
虽然背页没有自己的上传API,但Dropbox。用它把文件放进背页,
现在你可以上传文件了!HTTP是有据可查,但是Python至少有一个不错的SDK。所以对我来说,程序上传工作到
pip install dropboximport dropbox
from pathlib import Path
from io import BytesIO
import matplotlib.pyplot as plt
def upload(ax, project, path):
bs = BytesIO()
format = path.split('.')[-1]
ax.figure.savefig(bs, bbox_inches='tight', format=format)
token = Path('token.txt').read_text()
dbx = dropbox.Dropbox(token)
# Will throw an UploadError if it fails
dbx.files_upload(
f=bs.getvalue(),
path=f'/Apps/Overleaf/{project}/{path}',
mode=dropbox.files.WriteMode.overwrite)
if __name__ == '__main__':
fig, ax = plt.subplots()
upload(ax, 'project_name', 'images/test.png')https://stackoverflow.com/questions/65042888
复制相似问题