Problem While Importing Videos Using the API: The thumbnails aren't being imported

Hello everyone!

I have a project (the programming language is Python) where I’m uploading videos from one application and migrating them to PeerTube. I’m using the « Import Video » API call and this is the data being passed to the API:

data = {
            'channelId': channel_id,
            'name': video['title'][:max_title_length]+'...' if len(video['title']) > max_title_length else video['title'],
            'targetUrl': videoUrl,
            'commentsEnabled': True,
            'downloadEnabled': video['can_download'],
            'language': 'en',
            'nsfw': False,
            'originallyPublishedAt': video['videoCreation'],
            'privacy': 4,
            'thumbnailfile': getImageBinary(video['images']['posterLandscapeThumbs']),
            'waitTranscoding': False,

Here is the « getImageBinary » function:

def getImageBinary(url):
    response = requests.get(url,stream=True)
    response.raw.decode_content = True
    with open(test_file,'wb') as out:
    with open(test_file,'rb') as file:
        png_encoded = base64.b64encode(
        encoded_b2 = "".join([format(n, '08b') for n in png_encoded])
        return encoded_b2

The « url » argument is the URL to the image that I want as the thumbnail. But to sum up what this function does:

  • It saves the image to a test file
  • Opens the file
  • And then returns the image as a binary string (as required in the API reference)

But the API doesn’t recognize it and auto-generates a thumbnail. I’ve tried passing in a byte string, binary string (above), and the URL but none of those formats were valid to the API.

Thank you all for your time. If you have any solutions or suggestions, please let me know.

The above issue isn’t very well structured, see my revised topic here: PeerTube API Video Import: What is the Thumbnail Format?