# read file to add to item thisFile = open(fullPath, 'rb') contents = thisFile.read() # make sure we're posting the file to the right item fields = {"collection": { "html":False, "id":subDirMapping[subDir], # the collection ID "resource":"collections" }, "item": { "html":False, "id": itemId, # the item ID } } data = json.dumps(fields) # post the file response, content = client.post_file(data, filename, contents) print(response) for subDir in subDirMapping: thisSubDir = os.path.join(dirBase, str(subDir)) if os.path.exists(thisSubDir): files = os.listdir(thisSubDir) for filename in files: fullPath = os.path.join(thisSubDir, filename) if "image" in client.get_content_type(fullPath): newItem(fullPath, subDir, filename)