I’m new to the Kaltura API and I’m working on a process to create a media entry/upload data to it. I’m using the Kaltura API client in Python, Python 3.6 with the most recent Kaltura client version.
TL;DR is there a way I can start with a bytes object and use that as the fileData without writing it to a file first just to open it up so I have a io.BufferedReader?
The longer story:
The files that I’m working with are being retrieved from another API as bytes. I’m not reading them from a file. Therefore, what I tried to do to in order to use it in
uploadToken.upload was create an io.BytesIO object and passing that in place of the fileData (where it would normally be an io.BufferedReader). Here is a code snippet (token is already created here):
file_io = BytesIO(file_bytes) result = client.uploadToken.upload(token.id, file_io, False, True, -1)
This produces the following traceback:
Traceback (most recent call last): File "[redacted]/.venv/lib/python3.6/site-packages/KalturaClient/Client.py", line 324, in parsePostResult resultXml = etree.fromstring(postResult) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/xml/etree/ElementTree.py", line 1315, in XML return parser.close() File "<string>", line None xml.etree.ElementTree.ParseError: no element found: line 1, column 0 During handling of the above exception, another exception occurred: Traceback (most recent call last): File [redacted], line 97, in [redacted] result = client.uploadToken.upload(token.id, file_io, False, True, -1) File "[redacted]/.venv/lib/python3.6/site-packages/KalturaClient/Plugins/Core.py", line 66597, in upload resultNode = self.client.doQueue() File "[redacted]/.venv/lib/python3.6/site-packages/KalturaClient/Client.py", line 382, in doQueue resultNode = self.parsePostResult(postResult) File "[redacted]/.venv/lib/python3.6/site-packages/KalturaClient/Client.py", line 327, in parsePostResult e, KalturaClientException.ERROR_INVALID_XML) KalturaClient.exceptions.KalturaClientException: no element found: line 1, column 0 (-2)
It works if I open a file and pass the io.BufferedReader, but it doesn’t work with this method. I have also tried using
file_io.getbuffer() and passing that in, but that produces a
memoryview object that causes an error during encoding. I tried creating a io.BufferedReader object with my bytes object but got stuck where it wants a io.RawIOBase passed in, but there is no public constructor for RawIOBase.
I admittedly don’t work with files a whole lot and don’t have a ton of experience with I/O so it’s entirely possible and even probable that I’m doing something dumb. Please correct me if so!
I would really prefer to not write my bytes into a file just for the purpose of opening it.
I also tried hitting the API endpoint directly JUST for the uploadToken.upload step (i.e. POST https://www.kaltura.com/api_v3/service/uploadtoken/action/upload) and doing everything else as normal. For fileData I tried 2 different things 2 different times: I tried just passing the bytes, and I tried creating a dictionary with 1 key–
fileData and the value as the bytes object. There were no errors, but the media (which is a pretty small video file) has shown as processing for about 12 hours, so I’m thinking that didn’t work.