Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

Visual FoxPro Examples

Web API Categories

ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Cloud Signature CSC
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text
HTTP

HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
MS Storage Providers
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
Secrets
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

(Visual FoxPro) WordPress Media Upload

See more WordPress Examples

Demonstrates how to upload a media file to WordPress.

For more information, see https://developer.wordpress.org/rest-api/reference/media/#create-a-media-item

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

LOCAL loHttp
LOCAL loReq
LOCAL lnSuccess
LOCAL loResp
LOCAL loJsonResponse
LOCAL loDate_gmt
LOCAL lcHref
LOCAL lnEmbeddable
LOCAL lcName
LOCAL lnTemplated
LOCAL lnId
LOCAL lcDate
LOCAL lcGuidRendered
LOCAL lcGuidRaw
LOCAL lcModified
LOCAL lcModified_gmt
LOCAL lcSlug
LOCAL lcStatus
LOCAL lcV_type
LOCAL lcLink
LOCAL lcTitleRaw
LOCAL lcTitleRendered
LOCAL lnAuthor
LOCAL lcComment_status
LOCAL lcPing_status
LOCAL lcTemplate
LOCAL lcPermalink_template
LOCAL lcGenerated_slug
LOCAL lcDescriptionRaw
LOCAL lcDescriptionRendered
LOCAL lcCaptionRaw
LOCAL lcCaptionRendered
LOCAL lcAlt_text
LOCAL lcMedia_type
LOCAL lcMime_type
LOCAL lnMedia_detailsWidth
LOCAL lnMedia_detailsHeight
LOCAL lcMedia_detailsFile
LOCAL lcMedia_detailsSizesWoocommerce_gallery_thumbnailFile
LOCAL lnMedia_detailsSizesWoocommerce_gallery_thumbnailWidth
LOCAL lnMedia_detailsSizesWoocommerce_gallery_thumbnailHeight
LOCAL lcMedia_detailsSizesWoocommerce_gallery_thumbnailMime_type
LOCAL lcMedia_detailsSizesWoocommerce_gallery_thumbnailSource_url
LOCAL lcMedia_detailsSizesShop_thumbnailFile
LOCAL lnMedia_detailsSizesShop_thumbnailWidth
LOCAL lnMedia_detailsSizesShop_thumbnailHeight
LOCAL lcMedia_detailsSizesShop_thumbnailMime_type
LOCAL lcMedia_detailsSizesShop_thumbnailSource_url
LOCAL lcMedia_detailsSizesFullFile
LOCAL lnMedia_detailsSizesFullWidth
LOCAL lnMedia_detailsSizesFullHeight
LOCAL lcMedia_detailsSizesFullMime_type
LOCAL lcMedia_detailsSizesFullSource_url
LOCAL lcMedia_detailsImage_metaAperture
LOCAL lcMedia_detailsImage_metaCredit
LOCAL lcMedia_detailsImage_metaCamera
LOCAL lcMedia_detailsImage_metaCaption
LOCAL lcMedia_detailsImage_metaCreated_timestamp
LOCAL lcMedia_detailsImage_metaCopyright
LOCAL lcMedia_detailsImage_metaFocal_length
LOCAL lcMedia_detailsImage_metaIso
LOCAL lcMedia_detailsImage_metaShutter_speed
LOCAL lcMedia_detailsImage_metaTitle
LOCAL lcMedia_detailsImage_metaOrientation
LOCAL lcPost
LOCAL lcSource_url
LOCAL i
LOCAL lnCount_i

* This example requires the Chilkat API to have been previously unlocked.
* See Global Unlock Sample for sample code.

* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.Http')
loHttp = CreateObject('Chilkat.Http')

* This example will use WordPress username / Application password authentication using the "Applications Password" plugin.
* See https://wordpress.org/plugins/application-passwords/

* Use your WordPress login, such as "admin", not the application name.
loHttp.Login = "wp_username"
* Use the application password, such as "Nths RwVH eDJ4 weNZ orMN jabq"
loHttp.Password = "app_password"
loHttp.BasicAuth = 1

* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.HttpRequest')
loReq = CreateObject('Chilkat.HttpRequest')
loReq.HttpVerb = "POST"

* Use the Content-Type that corresponds to the type of file you are uploading.

* WordPress supports uploading the following file types:

* Images
* 
*     .jpg  (image/jpg)
*     .jpeg  (image/jpeg)
*     .png  (image/png)
*     .gif  (image/gif)
*     .ico (image/x-icon)
* 
* Documents
* 
*     .pdf (applicatin/pdf)
*     .doc, .docx (application/msword)
*     .ppt, .pptx, .pps, .ppsx (application/mspowerpoint)
*     .odt 
*     .xls, .xlsx (application/msexcel)
*     .psd (??? image/vnd.adobe.photoshop,application/x-photoshop,application/photoshop,application/psd,image/psd)
* 
* Audio
* 
*     .mp3 (audio/mpeg)
*     .m4a
*     .ogg
*     .wav (audio/wav)
* 
* Video
* 
*     .mp4, .m4v (video/mp4)
*     .mov (video/quicktime)
*     .wmv (video/x-ms-wmv)
*     .avi (video/avi)
*     .mpg (video/mpeg)
*     .ogv 
*     .3gp 
*     .3g2 

loReq.ContentType = "image/jpg"
loReq.Path = "/wp-json/wp/v2/media"

lnSuccess = loReq.LoadBodyFromFile("qa_data/jpg/starfish.jpg")
IF (lnSuccess = 0) THEN
    ? loReq.LastErrorText
    RELEASE loHttp
    RELEASE loReq
    CANCEL
ENDIF

loReq.AddHeader("Content-Disposition","attachment; filename=starfish.jpg")

loReq.AddHeader("Expect","100-continue")

loResp = loHttp.SynchronousRequest("www.yourserver.com",443,1,loReq)
IF (loHttp.LastMethodSuccess <> 1) THEN
    ? loHttp.LastErrorText
    RELEASE loHttp
    RELEASE loReq
    CANCEL
ENDIF

? "HTTP response status: " + STR(loResp.StatusCode)

* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.JsonObject')
loJsonResponse = CreateObject('Chilkat.JsonObject')
loJsonResponse.Load(loResp.BodyStr)
RELEASE loResp

loJsonResponse.EmitCompact = 0
? loJsonResponse.Emit()

* Sample JSON response:
* (Sample code for parsing the JSON response is shown below)

* {
*   "id": 1915,
*   "date": "2021-01-19T18:25:01",
*   "date_gmt": "2021-01-20T01:25:01",
*   "guid": {
*     "rendered": "http:\/\/cknotes.com\/wp-content\/uploads\/2021\/01\/starfish.jpg",
*     "raw": "http:\/\/cknotes.com\/wp-content\/uploads\/2021\/01\/starfish.jpg"
*   },
*   "modified": "2021-01-19T18:25:01",
*   "modified_gmt": "2021-01-20T01:25:01",
*   "slug": "starfish",
*   "status": "inherit",
*   "type": "attachment",
*   "link": "https:\/\/cknotes.com\/starfish\/",
*   "title": {
*     "raw": "starfish",
*     "rendered": "starfish"
*   },
*   "author": 1,
*   "comment_status": "closed",
*   "ping_status": "closed",
*   "template": "",
*   "meta": [
*   ],
*   "permalink_template": "https:\/\/cknotes.com\/?attachment_id=1915",
*   "generated_slug": "starfish",
*   "description": {
*     "raw": "",
*     "rendered": "<p class=\"attachment\"><a href='https:\/\/cknotes.com\/wp-content\/uploads\/2021\/01\/starfish.jpg'><img width=\"120\" height=\"120\" src=\"https:\/\/cknotes.com\/wp-content\/uploads\/2021\/01\/starfish.jpg\" class=\"attachment-medium size-medium\" alt=\"\" loading=\"lazy\" srcset=\"http:\/\/cknotes.com\/wp-content\/uploads\/2021\/01\/starfish.jpg 120w, http:\/\/cknotes.com\/wp-content\/uploads\/2021\/01\/starfish-100x100.jpg 100w\" sizes=\"(max-width: 120px) 100vw, 120px\" \/><\/a><\/p>\n"
*   },
*   "caption": {
*     "raw": "",
*     "rendered": ""
*   },
*   "alt_text": "",
*   "media_type": "image",
*   "mime_type": "image\/jpeg",
*   "media_details": {
*     "width": 120,
*     "height": 120,
*     "file": "2021\/01\/starfish.jpg",
*     "sizes": {
*       "woocommerce_gallery_thumbnail": {
*         "file": "starfish-100x100.jpg",
*         "width": 100,
*         "height": 100,
*         "mime_type": "image\/jpeg",
*         "source_url": "https:\/\/cknotes.com\/wp-content\/uploads\/2021\/01\/starfish-100x100.jpg"
*       },
*       "shop_thumbnail": {
*         "file": "starfish-100x100.jpg",
*         "width": 100,
*         "height": 100,
*         "mime_type": "image\/jpeg",
*         "source_url": "https:\/\/cknotes.com\/wp-content\/uploads\/2021\/01\/starfish-100x100.jpg"
*       },
*       "full": {
*         "file": "starfish.jpg",
*         "width": 120,
*         "height": 120,
*         "mime_type": "image\/jpeg",
*         "source_url": "https:\/\/cknotes.com\/wp-content\/uploads\/2021\/01\/starfish.jpg"
*       }
*     },
*     "image_meta": {
*       "aperture": "0",
*       "credit": "",
*       "camera": "",
*       "caption": "",
*       "created_timestamp": "0",
*       "copyright": "",
*       "focal_length": "0",
*       "iso": "0",
*       "shutter_speed": "0",
*       "title": "",
*       "orientation": "0",
*       "keywords": [
*       ]
*     }
*   },
*   "post": null,
*   "source_url": "https:\/\/cknotes.com\/wp-content\/uploads\/2021\/01\/starfish.jpg",
*   "missing_image_sizes": [
*   ],
*   "_links": {
*     "self": [
*       {
*         "href": "https:\/\/cknotes.com\/wp-json\/wp\/v2\/media\/1915"
*       }
*     ],
*     "collection": [
*       {
*         "href": "https:\/\/cknotes.com\/wp-json\/wp\/v2\/media"
*       }
*     ],
*     "about": [
*       {
*         "href": "https:\/\/cknotes.com\/wp-json\/wp\/v2\/types\/attachment"
*       }
*     ],
*     "author": [
*       {
*         "embeddable": true,
*         "href": "https:\/\/cknotes.com\/wp-json\/wp\/v2\/users\/1"
*       }
*     ],
*     "replies": [
*       {
*         "embeddable": true,
*         "href": "https:\/\/cknotes.com\/wp-json\/wp\/v2\/comments?post=1915"
*       }
*     ],
*     "wp:action-unfiltered-html": [
*       {
*         "href": "https:\/\/cknotes.com\/wp-json\/wp\/v2\/media\/1915"
*       }
*     ],
*     "wp:action-assign-author": [
*       {
*         "href": "https:\/\/cknotes.com\/wp-json\/wp\/v2\/media\/1915"
*       }
*     ],
*     "curies": [
*       {
*         "name": "wp",
*         "href": "https:\/\/api.w.org\/{rel}",
*         "templated": true
*       }
*     ]
*   }
* }

* Sample code for parsing the JSON response...
* Use the following online tool to generate parsing code from sample JSON:
* Generate Parsing Code from JSON

* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.DtObj')
loDate_gmt = CreateObject('Chilkat.DtObj')

lnId = loJsonResponse.IntOf("id")
lcDate = loJsonResponse.StringOf("date")
loJsonResponse.DtOf("date_gmt",0,loDate_gmt)
lcGuidRendered = loJsonResponse.StringOf("guid.rendered")
lcGuidRaw = loJsonResponse.StringOf("guid.raw")
lcModified = loJsonResponse.StringOf("modified")
lcModified_gmt = loJsonResponse.StringOf("modified_gmt")
lcSlug = loJsonResponse.StringOf("slug")
lcStatus = loJsonResponse.StringOf("status")
lcV_type = loJsonResponse.StringOf("type")
lcLink = loJsonResponse.StringOf("link")
lcTitleRaw = loJsonResponse.StringOf("title.raw")
lcTitleRendered = loJsonResponse.StringOf("title.rendered")
lnAuthor = loJsonResponse.IntOf("author")
lcComment_status = loJsonResponse.StringOf("comment_status")
lcPing_status = loJsonResponse.StringOf("ping_status")
lcTemplate = loJsonResponse.StringOf("template")
lcPermalink_template = loJsonResponse.StringOf("permalink_template")
lcGenerated_slug = loJsonResponse.StringOf("generated_slug")
lcDescriptionRaw = loJsonResponse.StringOf("description.raw")
lcDescriptionRendered = loJsonResponse.StringOf("description.rendered")
lcCaptionRaw = loJsonResponse.StringOf("caption.raw")
lcCaptionRendered = loJsonResponse.StringOf("caption.rendered")
lcAlt_text = loJsonResponse.StringOf("alt_text")
lcMedia_type = loJsonResponse.StringOf("media_type")
lcMime_type = loJsonResponse.StringOf("mime_type")
lnMedia_detailsWidth = loJsonResponse.IntOf("media_details.width")
lnMedia_detailsHeight = loJsonResponse.IntOf("media_details.height")
lcMedia_detailsFile = loJsonResponse.StringOf("media_details.file")
lcMedia_detailsSizesWoocommerce_gallery_thumbnailFile = loJsonResponse.StringOf("media_details.sizes.woocommerce_gallery_thumbnail.file")
lnMedia_detailsSizesWoocommerce_gallery_thumbnailWidth = loJsonResponse.IntOf("media_details.sizes.woocommerce_gallery_thumbnail.width")
lnMedia_detailsSizesWoocommerce_gallery_thumbnailHeight = loJsonResponse.IntOf("media_details.sizes.woocommerce_gallery_thumbnail.height")
lcMedia_detailsSizesWoocommerce_gallery_thumbnailMime_type = loJsonResponse.StringOf("media_details.sizes.woocommerce_gallery_thumbnail.mime_type")
lcMedia_detailsSizesWoocommerce_gallery_thumbnailSource_url = loJsonResponse.StringOf("media_details.sizes.woocommerce_gallery_thumbnail.source_url")
lcMedia_detailsSizesShop_thumbnailFile = loJsonResponse.StringOf("media_details.sizes.shop_thumbnail.file")
lnMedia_detailsSizesShop_thumbnailWidth = loJsonResponse.IntOf("media_details.sizes.shop_thumbnail.width")
lnMedia_detailsSizesShop_thumbnailHeight = loJsonResponse.IntOf("media_details.sizes.shop_thumbnail.height")
lcMedia_detailsSizesShop_thumbnailMime_type = loJsonResponse.StringOf("media_details.sizes.shop_thumbnail.mime_type")
lcMedia_detailsSizesShop_thumbnailSource_url = loJsonResponse.StringOf("media_details.sizes.shop_thumbnail.source_url")
lcMedia_detailsSizesFullFile = loJsonResponse.StringOf("media_details.sizes.full.file")
lnMedia_detailsSizesFullWidth = loJsonResponse.IntOf("media_details.sizes.full.width")
lnMedia_detailsSizesFullHeight = loJsonResponse.IntOf("media_details.sizes.full.height")
lcMedia_detailsSizesFullMime_type = loJsonResponse.StringOf("media_details.sizes.full.mime_type")
lcMedia_detailsSizesFullSource_url = loJsonResponse.StringOf("media_details.sizes.full.source_url")
lcMedia_detailsImage_metaAperture = loJsonResponse.StringOf("media_details.image_meta.aperture")
lcMedia_detailsImage_metaCredit = loJsonResponse.StringOf("media_details.image_meta.credit")
lcMedia_detailsImage_metaCamera = loJsonResponse.StringOf("media_details.image_meta.camera")
lcMedia_detailsImage_metaCaption = loJsonResponse.StringOf("media_details.image_meta.caption")
lcMedia_detailsImage_metaCreated_timestamp = loJsonResponse.StringOf("media_details.image_meta.created_timestamp")
lcMedia_detailsImage_metaCopyright = loJsonResponse.StringOf("media_details.image_meta.copyright")
lcMedia_detailsImage_metaFocal_length = loJsonResponse.StringOf("media_details.image_meta.focal_length")
lcMedia_detailsImage_metaIso = loJsonResponse.StringOf("media_details.image_meta.iso")
lcMedia_detailsImage_metaShutter_speed = loJsonResponse.StringOf("media_details.image_meta.shutter_speed")
lcMedia_detailsImage_metaTitle = loJsonResponse.StringOf("media_details.image_meta.title")
lcMedia_detailsImage_metaOrientation = loJsonResponse.StringOf("media_details.image_meta.orientation")
lcPost = loJsonResponse.StringOf("post")
lcSource_url = loJsonResponse.StringOf("source_url")
i = 0
lnCount_i = loJsonResponse.SizeOfArray("meta")
DO WHILE i < lnCount_i
    loJsonResponse.I = i
    i = i + 1
ENDDO
i = 0
lnCount_i = loJsonResponse.SizeOfArray("media_details.image_meta.keywords")
DO WHILE i < lnCount_i
    loJsonResponse.I = i
    i = i + 1
ENDDO
i = 0
lnCount_i = loJsonResponse.SizeOfArray("missing_image_sizes")
DO WHILE i < lnCount_i
    loJsonResponse.I = i
    i = i + 1
ENDDO
i = 0
lnCount_i = loJsonResponse.SizeOfArray("_links.self")
DO WHILE i < lnCount_i
    loJsonResponse.I = i
    lcHref = loJsonResponse.StringOf("_links.self[i].href")
    i = i + 1
ENDDO
i = 0
lnCount_i = loJsonResponse.SizeOfArray("_links.collection")
DO WHILE i < lnCount_i
    loJsonResponse.I = i
    lcHref = loJsonResponse.StringOf("_links.collection[i].href")
    i = i + 1
ENDDO
i = 0
lnCount_i = loJsonResponse.SizeOfArray("_links.about")
DO WHILE i < lnCount_i
    loJsonResponse.I = i
    lcHref = loJsonResponse.StringOf("_links.about[i].href")
    i = i + 1
ENDDO
i = 0
lnCount_i = loJsonResponse.SizeOfArray("_links.author")
DO WHILE i < lnCount_i
    loJsonResponse.I = i
    lnEmbeddable = loJsonResponse.BoolOf("_links.author[i].embeddable")
    lcHref = loJsonResponse.StringOf("_links.author[i].href")
    i = i + 1
ENDDO
i = 0
lnCount_i = loJsonResponse.SizeOfArray("_links.replies")
DO WHILE i < lnCount_i
    loJsonResponse.I = i
    lnEmbeddable = loJsonResponse.BoolOf("_links.replies[i].embeddable")
    lcHref = loJsonResponse.StringOf("_links.replies[i].href")
    i = i + 1
ENDDO
i = 0
lnCount_i = loJsonResponse.SizeOfArray("_links.wp:action-unfiltered-html")
DO WHILE i < lnCount_i
    loJsonResponse.I = i
    lcHref = loJsonResponse.StringOf("_links.wp:action-unfiltered-html[i].href")
    i = i + 1
ENDDO
i = 0
lnCount_i = loJsonResponse.SizeOfArray("_links.wp:action-assign-author")
DO WHILE i < lnCount_i
    loJsonResponse.I = i
    lcHref = loJsonResponse.StringOf("_links.wp:action-assign-author[i].href")
    i = i + 1
ENDDO
i = 0
lnCount_i = loJsonResponse.SizeOfArray("_links.curies")
DO WHILE i < lnCount_i
    loJsonResponse.I = i
    lcName = loJsonResponse.StringOf("_links.curies[i].name")
    lcHref = loJsonResponse.StringOf("_links.curies[i].href")
    lnTemplated = loJsonResponse.BoolOf("_links.curies[i].templated")
    i = i + 1
ENDDO

RELEASE loHttp
RELEASE loReq
RELEASE loJsonResponse
RELEASE loDate_gmt


 

© 2000-2024 Chilkat Software, Inc. All Rights Reserved.