api.content.create(type='File' ... isn't enough.
based on this https://stackoverflow.com/a/38352200
The process should involve the following:
- open the
file as data (standard python)
- use api.content.create to create a
file object (this will hold the file)
- assign the
file as data to the
container = self.context
# step 1 - open file as data
pdf_file_data = open(path_to_file, 'r').read()
# step 2 - create the file object
file_obj = api.content.create(
title="my pdf file",
description="just a demo of a pdf file containing picture of a naseberry",
excludeFromNav=True # this is optional but helpful
# step 3 - assign the file as data to the file object
# you'll need to import NamedBlobFile (there may be another way, but this works reliably)
file_obj.file = NamedBlobFile(
filename=unicode(file_obj.id), # needs to be unicode
Your file is html which would use a different contentType.
while this works you may want to set the file name based on something other than the file_obj.id.