From 17c822e86c4898641d793be1c2426642d42cca9b Mon Sep 17 00:00:00 2001 From: Shroominic Date: Wed, 12 Jun 2024 18:52:44 -0700 Subject: [PATCH] update with workaround file upload --- examples/big_upload.py | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/examples/big_upload.py b/examples/big_upload.py index 075de0c..e7f562f 100644 --- a/examples/big_upload.py +++ b/examples/big_upload.py @@ -1,7 +1,36 @@ from codeboxapi import CodeBox + +def url_upload(codebox, url: str) -> None: + codebox.run( + """ +import requests + +def download_file_from_url(url: str) -> None: + response = requests.get(url, stream=True) + response.raise_for_status() + file_name = url.split('/')[-1] + with open('./' + file_name, 'wb') as file: + for chunk in response.iter_content(chunk_size=8192): + if chunk: + file.write(chunk) + """ + ) + print(codebox.run(f"download_file_from_url('{url}')")) + + with CodeBox() as codebox: - with open("examples/assets/swedata/train/data-00000-of-00001.arrow", "rb") as file: - codebox.upload(file.name, file.read(), timeout=900) + url_upload( + codebox, + "https://codeboxapistorage.blob.core.windows.net/bucket/data-test.arrow", + ) + print(codebox.list_files()) + url_upload( + codebox, + "https://codeboxapistorage.blob.core.windows.net/bucket/data-train.arrow", + ) print(codebox.list_files()) + + codebox.run("import os") + print(codebox.run("print(os.listdir())"))