如何使用 project-lib python 将二进制文件保存到我的项目资产中?

How can I save a binary file to my project assets using project-lib python?

项目库文档展示了如何将 pandas 数据框保存到项目资产中:

 # Import the lib
 from project_lib import Project
 project = Project(sc,"<ProjectId>", "<ProjectToken>")

 # let's assume you have the pandas DataFrame  pandas_df which contains the data
 # you want to save in your object storage as a csv file
 project.save_data("file_name.csv", pandas_df.to_csv())

 # the function returns a dict which contains the asset_id, bucket_name and file_name
 # upon successful saving of the data

但是,如果我有一个本地文件...

! wget url_to_binary_file

我怎样才能将该文件上传到项目的资产中?

我需要以字节形式读取文件。请注意,这会将文件读入内存,如果您的文件大于可用内存,请不要尝试:

import io

filename = ‘thefilename’
with open(filename, 'rb') as z:
        data = io.BytesIO(z.read())
        project.save_data(
            filename, data, set_project_asset=True, overwrite=True
        )