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

PowerBuilder 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
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

 

 

 

(PowerBuilder) 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

integer li_rc
oleobject loo_Http
oleobject loo_Req
integer li_Success
oleobject loo_Resp
oleobject loo_JsonResponse
oleobject loo_Date_gmt
string ls_Href
integer li_Embeddable
string ls_Name
integer li_Templated
integer li_Id
string ls_Date
string ls_GuidRendered
string ls_GuidRaw
string ls_Modified
string ls_Modified_gmt
string ls_Slug
string ls_Status
string ls_V_type
string ls_Link
string ls_TitleRaw
string ls_TitleRendered
integer li_Author
string ls_Comment_status
string ls_Ping_status
string ls_Template
string ls_Permalink_template
string ls_Generated_slug
string ls_DescriptionRaw
string ls_DescriptionRendered
string ls_CaptionRaw
string ls_CaptionRendered
string ls_Alt_text
string ls_Media_type
string ls_Mime_type
integer li_Media_detailsWidth
integer li_Media_detailsHeight
string ls_Media_detailsFile
string ls_Media_detailsSizesWoocommerce_gallery_thumbnailFile
integer li_Media_detailsSizesWoocommerce_gallery_thumbnailWidth
integer li_Media_detailsSizesWoocommerce_gallery_thumbnailHeight
string ls_Media_detailsSizesWoocommerce_gallery_thumbnailMime_type
string ls_Media_detailsSizesWoocommerce_gallery_thumbnailSource_url
string ls_Media_detailsSizesShop_thumbnailFile
integer li_Media_detailsSizesShop_thumbnailWidth
integer li_Media_detailsSizesShop_thumbnailHeight
string ls_Media_detailsSizesShop_thumbnailMime_type
string ls_Media_detailsSizesShop_thumbnailSource_url
string ls_Media_detailsSizesFullFile
integer li_Media_detailsSizesFullWidth
integer li_Media_detailsSizesFullHeight
string ls_Media_detailsSizesFullMime_type
string ls_Media_detailsSizesFullSource_url
string ls_Media_detailsImage_metaAperture
string ls_Media_detailsImage_metaCredit
string ls_Media_detailsImage_metaCamera
string ls_Media_detailsImage_metaCaption
string ls_Media_detailsImage_metaCreated_timestamp
string ls_Media_detailsImage_metaCopyright
string ls_Media_detailsImage_metaFocal_length
string ls_Media_detailsImage_metaIso
string ls_Media_detailsImage_metaShutter_speed
string ls_Media_detailsImage_metaTitle
string ls_Media_detailsImage_metaOrientation
string ls_Post
string ls_Source_url
integer i
integer li_Count_i

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

loo_Http = create oleobject
// Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
    destroy loo_Http
    MessageBox("Error","Connecting to COM object failed")
    return
end if

// 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.
loo_Http.Login = "wp_username"
// Use the application password, such as "Nths RwVH eDJ4 weNZ orMN jabq"
loo_Http.Password = "app_password"
loo_Http.BasicAuth = 1

loo_Req = create oleobject
// Use "Chilkat_9_5_0.HttpRequest" for versions of Chilkat < 10.0.0
li_rc = loo_Req.ConnectToNewObject("Chilkat.HttpRequest")

loo_Req.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 

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

li_Success = loo_Req.LoadBodyFromFile("qa_data/jpg/starfish.jpg")
if li_Success = 0 then
    Write-Debug loo_Req.LastErrorText
    destroy loo_Http
    destroy loo_Req
    return
end if

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

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

loo_Resp = loo_Http.SynchronousRequest("www.yourserver.com",443,1,loo_Req)
if loo_Http.LastMethodSuccess <> 1 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_Req
    return
end if

Write-Debug "HTTP response status: " + string(loo_Resp.StatusCode)

loo_JsonResponse = create oleobject
// Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
li_rc = loo_JsonResponse.ConnectToNewObject("Chilkat.JsonObject")

loo_JsonResponse.Load(loo_Resp.BodyStr)
destroy loo_Resp

loo_JsonResponse.EmitCompact = 0
Write-Debug loo_JsonResponse.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

loo_Date_gmt = create oleobject
// Use "Chilkat_9_5_0.DtObj" for versions of Chilkat < 10.0.0
li_rc = loo_Date_gmt.ConnectToNewObject("Chilkat.DtObj")

li_Id = loo_JsonResponse.IntOf("id")
ls_Date = loo_JsonResponse.StringOf("date")
loo_JsonResponse.DtOf("date_gmt",0,loo_Date_gmt)
ls_GuidRendered = loo_JsonResponse.StringOf("guid.rendered")
ls_GuidRaw = loo_JsonResponse.StringOf("guid.raw")
ls_Modified = loo_JsonResponse.StringOf("modified")
ls_Modified_gmt = loo_JsonResponse.StringOf("modified_gmt")
ls_Slug = loo_JsonResponse.StringOf("slug")
ls_Status = loo_JsonResponse.StringOf("status")
ls_V_type = loo_JsonResponse.StringOf("type")
ls_Link = loo_JsonResponse.StringOf("link")
ls_TitleRaw = loo_JsonResponse.StringOf("title.raw")
ls_TitleRendered = loo_JsonResponse.StringOf("title.rendered")
li_Author = loo_JsonResponse.IntOf("author")
ls_Comment_status = loo_JsonResponse.StringOf("comment_status")
ls_Ping_status = loo_JsonResponse.StringOf("ping_status")
ls_Template = loo_JsonResponse.StringOf("template")
ls_Permalink_template = loo_JsonResponse.StringOf("permalink_template")
ls_Generated_slug = loo_JsonResponse.StringOf("generated_slug")
ls_DescriptionRaw = loo_JsonResponse.StringOf("description.raw")
ls_DescriptionRendered = loo_JsonResponse.StringOf("description.rendered")
ls_CaptionRaw = loo_JsonResponse.StringOf("caption.raw")
ls_CaptionRendered = loo_JsonResponse.StringOf("caption.rendered")
ls_Alt_text = loo_JsonResponse.StringOf("alt_text")
ls_Media_type = loo_JsonResponse.StringOf("media_type")
ls_Mime_type = loo_JsonResponse.StringOf("mime_type")
li_Media_detailsWidth = loo_JsonResponse.IntOf("media_details.width")
li_Media_detailsHeight = loo_JsonResponse.IntOf("media_details.height")
ls_Media_detailsFile = loo_JsonResponse.StringOf("media_details.file")
ls_Media_detailsSizesWoocommerce_gallery_thumbnailFile = loo_JsonResponse.StringOf("media_details.sizes.woocommerce_gallery_thumbnail.file")
li_Media_detailsSizesWoocommerce_gallery_thumbnailWidth = loo_JsonResponse.IntOf("media_details.sizes.woocommerce_gallery_thumbnail.width")
li_Media_detailsSizesWoocommerce_gallery_thumbnailHeight = loo_JsonResponse.IntOf("media_details.sizes.woocommerce_gallery_thumbnail.height")
ls_Media_detailsSizesWoocommerce_gallery_thumbnailMime_type = loo_JsonResponse.StringOf("media_details.sizes.woocommerce_gallery_thumbnail.mime_type")
ls_Media_detailsSizesWoocommerce_gallery_thumbnailSource_url = loo_JsonResponse.StringOf("media_details.sizes.woocommerce_gallery_thumbnail.source_url")
ls_Media_detailsSizesShop_thumbnailFile = loo_JsonResponse.StringOf("media_details.sizes.shop_thumbnail.file")
li_Media_detailsSizesShop_thumbnailWidth = loo_JsonResponse.IntOf("media_details.sizes.shop_thumbnail.width")
li_Media_detailsSizesShop_thumbnailHeight = loo_JsonResponse.IntOf("media_details.sizes.shop_thumbnail.height")
ls_Media_detailsSizesShop_thumbnailMime_type = loo_JsonResponse.StringOf("media_details.sizes.shop_thumbnail.mime_type")
ls_Media_detailsSizesShop_thumbnailSource_url = loo_JsonResponse.StringOf("media_details.sizes.shop_thumbnail.source_url")
ls_Media_detailsSizesFullFile = loo_JsonResponse.StringOf("media_details.sizes.full.file")
li_Media_detailsSizesFullWidth = loo_JsonResponse.IntOf("media_details.sizes.full.width")
li_Media_detailsSizesFullHeight = loo_JsonResponse.IntOf("media_details.sizes.full.height")
ls_Media_detailsSizesFullMime_type = loo_JsonResponse.StringOf("media_details.sizes.full.mime_type")
ls_Media_detailsSizesFullSource_url = loo_JsonResponse.StringOf("media_details.sizes.full.source_url")
ls_Media_detailsImage_metaAperture = loo_JsonResponse.StringOf("media_details.image_meta.aperture")
ls_Media_detailsImage_metaCredit = loo_JsonResponse.StringOf("media_details.image_meta.credit")
ls_Media_detailsImage_metaCamera = loo_JsonResponse.StringOf("media_details.image_meta.camera")
ls_Media_detailsImage_metaCaption = loo_JsonResponse.StringOf("media_details.image_meta.caption")
ls_Media_detailsImage_metaCreated_timestamp = loo_JsonResponse.StringOf("media_details.image_meta.created_timestamp")
ls_Media_detailsImage_metaCopyright = loo_JsonResponse.StringOf("media_details.image_meta.copyright")
ls_Media_detailsImage_metaFocal_length = loo_JsonResponse.StringOf("media_details.image_meta.focal_length")
ls_Media_detailsImage_metaIso = loo_JsonResponse.StringOf("media_details.image_meta.iso")
ls_Media_detailsImage_metaShutter_speed = loo_JsonResponse.StringOf("media_details.image_meta.shutter_speed")
ls_Media_detailsImage_metaTitle = loo_JsonResponse.StringOf("media_details.image_meta.title")
ls_Media_detailsImage_metaOrientation = loo_JsonResponse.StringOf("media_details.image_meta.orientation")
ls_Post = loo_JsonResponse.StringOf("post")
ls_Source_url = loo_JsonResponse.StringOf("source_url")
i = 0
li_Count_i = loo_JsonResponse.SizeOfArray("meta")
do while i < li_Count_i
    loo_JsonResponse.I = i
    i = i + 1
loop
i = 0
li_Count_i = loo_JsonResponse.SizeOfArray("media_details.image_meta.keywords")
do while i < li_Count_i
    loo_JsonResponse.I = i
    i = i + 1
loop
i = 0
li_Count_i = loo_JsonResponse.SizeOfArray("missing_image_sizes")
do while i < li_Count_i
    loo_JsonResponse.I = i
    i = i + 1
loop
i = 0
li_Count_i = loo_JsonResponse.SizeOfArray("_links.self")
do while i < li_Count_i
    loo_JsonResponse.I = i
    ls_Href = loo_JsonResponse.StringOf("_links.self[i].href")
    i = i + 1
loop
i = 0
li_Count_i = loo_JsonResponse.SizeOfArray("_links.collection")
do while i < li_Count_i
    loo_JsonResponse.I = i
    ls_Href = loo_JsonResponse.StringOf("_links.collection[i].href")
    i = i + 1
loop
i = 0
li_Count_i = loo_JsonResponse.SizeOfArray("_links.about")
do while i < li_Count_i
    loo_JsonResponse.I = i
    ls_Href = loo_JsonResponse.StringOf("_links.about[i].href")
    i = i + 1
loop
i = 0
li_Count_i = loo_JsonResponse.SizeOfArray("_links.author")
do while i < li_Count_i
    loo_JsonResponse.I = i
    li_Embeddable = loo_JsonResponse.BoolOf("_links.author[i].embeddable")
    ls_Href = loo_JsonResponse.StringOf("_links.author[i].href")
    i = i + 1
loop
i = 0
li_Count_i = loo_JsonResponse.SizeOfArray("_links.replies")
do while i < li_Count_i
    loo_JsonResponse.I = i
    li_Embeddable = loo_JsonResponse.BoolOf("_links.replies[i].embeddable")
    ls_Href = loo_JsonResponse.StringOf("_links.replies[i].href")
    i = i + 1
loop
i = 0
li_Count_i = loo_JsonResponse.SizeOfArray("_links.wp:action-unfiltered-html")
do while i < li_Count_i
    loo_JsonResponse.I = i
    ls_Href = loo_JsonResponse.StringOf("_links.wp:action-unfiltered-html[i].href")
    i = i + 1
loop
i = 0
li_Count_i = loo_JsonResponse.SizeOfArray("_links.wp:action-assign-author")
do while i < li_Count_i
    loo_JsonResponse.I = i
    ls_Href = loo_JsonResponse.StringOf("_links.wp:action-assign-author[i].href")
    i = i + 1
loop
i = 0
li_Count_i = loo_JsonResponse.SizeOfArray("_links.curies")
do while i < li_Count_i
    loo_JsonResponse.I = i
    ls_Name = loo_JsonResponse.StringOf("_links.curies[i].name")
    ls_Href = loo_JsonResponse.StringOf("_links.curies[i].href")
    li_Templated = loo_JsonResponse.BoolOf("_links.curies[i].templated")
    i = i + 1
loop


destroy loo_Http
destroy loo_Req
destroy loo_JsonResponse
destroy loo_Date_gmt

 

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