Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sandbox.upload_file assumes io.FileIO #36

Open
bengladwell opened this issue Aug 23, 2024 · 3 comments
Open

Sandbox.upload_file assumes io.FileIO #36

bengladwell opened this issue Aug 23, 2024 · 3 comments
Labels
improvement Improvement for current functionality

Comments

@bengladwell
Copy link

The Sandbox.upload_file method has the following signature:

def upload_file(self, file: IO, timeout: Optional[float] = TIMEOUT) -> str:

However, it's not true that file must simply be type IO. Because .name is called on that object:

        filename = path.basename(file.name)

it seems that the method actually expects the object to be of type FileIO, a subtype of IO and the type that you get when you use the builtin open function.

This is unwieldy when dealing with a file that is not stored on disk. In that case, I have access to the file's bytes and I have its filename. But I can't create a FileIO object to pass to upload_file without writing disk (creating a FileIO automatically writes to disk). In the meantime I am creating a subclass of BytesIO that has a name property. So, the duck type satisfies the requirements of upload_file. But I think it should be straightforward to upload a file that is not on disk.

@ValentaTomas ValentaTomas added the improvement Improvement for current functionality label Aug 31, 2024
@ValentaTomas
Copy link
Member

Hey @bengladwell, thank you for creating the issue!
This is something we are fixing in the Beta SDK (https://github.com/e2b-dev/E2B/blob/beta/packages/python-sdk/e2b/sandbox_sync/filesystem/filesystem.py#L102) because you are correct that this is very unwieldy.

The Beta releases of the Core SDK and Code Interpreter SDK should have this change already (https://e2b.dev/docs/guide/beta-migration#uploading-data-and-creating-files-in-sandbox).

@ValentaTomas
Copy link
Member

Hey @bengladwell were you able to resolve this?

@bengladwell
Copy link
Author

@ValentaTomas Thanks for checking in. I will migrating to the beta SDK next week, so hopefully I'll get it worked out then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement Improvement for current functionality
Projects
None yet
Development

No branches or pull requests

2 participants