PRO: Upload Image from JSON-data to WP-Media with twig-function “mediastore”

This page demonstrates how you can upload a Image to the WordPress-Library out of a JSON-feed

Input JSON:<br>
{{_context |json_encode}}<hr>

{# upload the image to the upload-page itself #}
{% set pgprop = wp_get_page_properties() %}
{% set parentPageId = pgprop.get_post.ID %} 

{# Title of the mediafile in the WP-Medialib #}
{% set mediatitle = "this-is-mediatitle" %}

{# FALSE: Store it always
TRUE: If there is already a mediafile with title 'mediatitle' do not store it
#}
{% set useExistingMediaFile = FALSE %}

{# only relevant if useExistingMediaFile=FALSE
TRUE: do not store but delete existing files with title 'mediatitle' #}
{% set deleteonly = FALSE %}

{# set post_excerpt / caption #}
{% set excerpt = "this is post_excerpt" %}

{# set post_content / description #}
{% set content = " this is content" %}

{# not used, set always to "" #}
{% set mime_type = "" %}

{# if '' the value of source of the mediafile is used from the JSON as is. 
If sourcetype="file" the plugin checks if such a file exists on the server:
If no such mediafile is on the server the mediastore is aborted without storing. 
This is helpful: If you have many mediafiles (1000s) in the JSON you might first download
the mediafiles with a PHP-Script without any WordPress-OVerhead (much faster). 
And then laod the images via WordPress and JCI-mediastore from the server without 
http-requests (also fast)#}
{% set sourcetype = "" %}

{# FALSE: Do not generate thumbnails - 
if you store many images this is importaint, as generating costs lots of performance / time #}
{% set generate_thumbnails = TRUE %}

{% set loadedimage = ((imageurl | mediastore(parentPageId, useExistingMediaFile, deleteonly, mediatitle, excerpt, content, mime_type, sourcetype, generate_thumbnails)) | json_decode) %}

Uploaded Images at <a href="{{loadedimage.jci.attachment_url }}" target="_blank2">{{loadedimage.jci.attachment_url }}</a><br>
<img src="{{loadedimage.jci.attachment_url }}">
<hr>

Complete WordPress-Response:<br>
{{ loadedimage | json_encode }}

Example in action:

Input JSON:
{"imagename":"JCI-Logo","imageurl":"http://api.json-content-importer.com/extra/api/image/jci-logo-144x144.png"}

Warning: checkdate() expects parameter 1 to be int, string given in /www/htdocs/w0135691/api.json-content-importer.com/wp-includes/functions.php on line 7069
Complete Wordpress-Response:
{"jci":{"file":"http://api.json-content-importer.com/extra/api/image/jci-logo-144x144.png","status":"ok","statusmsg":"ok","filename":"http-api.json-content-importer.com-extra-api-image-jci-logo-144x144.png","attachment_id":0,"attachment_url":false}}