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 file object
For example:
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(
type='File',
title="my pdf file",
description="just a demo of a pdf file containing picture of a naseberry",
safe_id=True,
container=container,
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(
data=pdf_file_data,
contentType='application/pdf',
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.