Problem in file upload

Guys how to upload a file via program. I tried the following syntax.

api.content.create(
type='File',
title='map',
file='/home/Plone/zinstance/map.html',
container=self.context)

See 'update 3'

sorry I couldnt understand . Can you explain a bit

api.content.create(type='File' ... isn't enough.

based on this https://stackoverflow.com/a/38352200

The process should involve the following:

  1. open the file as data (standard python)
  2. use api.content.create to create a file object (this will hold the file)
  3. 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.

Thank you to everyone who replied . I think I got the problem.