cog
87787f47 - Support URLFile in the upload_file function (#1985)

Commit
1 year ago
Support URLFile in the upload_file function (#1985) We would like `predict` functions to be able to return a remote URL rather than a local file on disk and have it behave like a file object. And when it is passed to the file uploader it will stream the file from the remote to the destination provided. ```py class Predictor(BasePredictor): def predict(self, **kwargs) -> File: return URLFile("https://replicate.delivery/czjl/9MBNrffKcxoqY0iprW66NF8MZaNeH322a27yE0sjFGtKMXLnA/hello.webp") ``` This PR adds an additional check to the `upload_file()` handler to call `fh.seekable()` before attempting to seek. This allows instances of `io.IOBase` that do not support seek (like `URLFile`) to be uploaded. We also add a `name` attribute to `URLFile`. This is used by the `upload_file` function to infer the file extension and mime type.
Author
Parents
Loading