Create Media
Uploads a media file to the WordPress media library, making it available for use in posts, pages, and as featured images.
Common Properties
- Name - The custom name of the node.
- Color - The custom color of the node.
- Delay Before (sec) - Waits in seconds before executing the node.
- Delay After (sec) - Waits in seconds after executing node.
- Continue On Error - Automation will continue regardless of any error. The default value is false.
If the ContinueOnError property is true, no error is caught when the project is executed, even if a Catch node is used.
Inputs
- Client Id - The client ID from the Connect node (optional if using direct credentials).
- File Path - Local file path of the media to upload (e.g., "/path/to/image.jpg").
- File Name - Name for the file in WordPress media library (e.g., "product-image.jpg").
Options
- Content Type - MIME type of the file. Options:
- default - Auto-detect content type (recommended)
- text/plain - Plain text files
- text/html - HTML files
- text/css - CSS stylesheets
- image/jpeg - JPEG images
- image/png - PNG images
- image/svg+xml - SVG images
- audio/mp4 - MP4 audio files
- video/mp4 - MP4 video files
- application/javascript - JavaScript files
- application/pdf - PDF documents
- application/zip - ZIP archives
- application/atom+xml - Atom feeds
- application/json - JSON files
- Site URL - (Optional) WordPress site URL. Use this if you want to authenticate directly without a Connect node.
- Credentials - (Optional) WordPress username and application password. Use this if you want to authenticate directly without a Connect node.
Output
- Media - The complete media object returned from WordPress, including the media ID, URL, dimensions, and all metadata.
How It Works
The Create Media node uploads a file to the WordPress media library using the WordPress REST API.
When executed, the node:
- Retrieves the authentication (either from Client Id or direct credentials)
- Reads the file from the specified local path
- Validates the file path and file name
- Sends a POST request to
/wp-json/wp/v2/mediaendpoint with the file data - Sets the appropriate Content-Type header
- Returns the created media object with URLs and metadata
Authentication Methods
Method 1: Using Connect Node (Recommended)
Connect → Store Client Id → Create Media (use Client Id)
Method 2: Direct Credentials
Provide both Site URL and Credentials directly in the node options.
Requirements
- A WordPress site with REST API enabled (WordPress 4.7+)
- Appropriate user permissions (author role or higher to upload media)
- Valid local file path with read permissions
- Supported file type (check WordPress media settings)
- File size within WordPress upload limits
Supported File Types
Common supported file types:
- Images: JPG, JPEG, PNG, GIF, SVG, WebP
- Documents: PDF, DOC, DOCX, PPT, PPTX, XLS, XLSX
- Audio: MP3, M4A, OGG, WAV
- Video: MP4, M4V, MOV, WMV, AVI
- Archives: ZIP
Actual supported file types depend on your WordPress configuration and may be restricted for security reasons.
Error Handling
The node will return specific errors in the following cases:
- Missing or empty File Path
- Missing or empty File Name
- File not found at specified path
- File read permission denied
- Unsupported file type
- File size exceeds WordPress upload limit
- Authentication failure
- Insufficient permissions to upload media
- Network connection errors
- WordPress REST API disabled
Usage Notes
- The File Path must be a valid local file system path
- File Name determines how the file appears in the WordPress media library
- Using "default" content type allows WordPress to auto-detect the file type
- The returned media object includes multiple image sizes for images
- Media files are immediately available after upload
- The media ID can be used as featured_media in posts
- WordPress may generate thumbnail and other sizes for images
Media Object Structure
The returned Media object includes:
- id - Unique media ID (use this for featured images)
- date - Upload date
- slug - URL-friendly identifier
- type - Media type (attachment)
- link - Public URL to the attachment page
- title - Media title object
- author - Uploader user ID
- mime_type - MIME type of the file
- media_type - Category (image, video, audio, file)
- source_url - Direct URL to the file
- media_details - Detailed metadata (dimensions, file size, etc.)
- alt_text - Alternative text for images
Example: Upload Image
Inputs:
- File Path: "/home/user/downloads/product.jpg"
- File Name: "product-image.jpg"
Options:
- Content Type: default (or image/jpeg)
Output - Media:
{
"id": 789,
"date": "2024-01-15T10:30:00",
"slug": "product-image",
"type": "attachment",
"link": "https://yoursite.com/product-image/",
"title": {
"rendered": "product-image"
},
"mime_type": "image/jpeg",
"media_type": "image",
"source_url": "https://yoursite.com/wp-content/uploads/2024/01/product-image.jpg",
"media_details": {
"width": 1920,
"height": 1080,
"file": "2024/01/product-image.jpg",
"sizes": {
"thumbnail": {
"file": "product-image-150x150.jpg",
"width": 150,
"height": 150,
"source_url": "https://yoursite.com/wp-content/uploads/2024/01/product-image-150x150.jpg"
},
"medium": {
"file": "product-image-300x169.jpg",
"width": 300,
"height": 169,
"source_url": "https://yoursite.com/wp-content/uploads/2024/01/product-image-300x169.jpg"
}
}
}
}
Example: Upload PDF Document
Inputs:
- File Path: "/data/reports/monthly-report.pdf"
- File Name: "january-2024-report.pdf"
Options:
- Content Type: application/pdf
Example: Upload and Use as Featured Image
Workflow:
1. Create Media
- File Path: "/images/hero.jpg"
- File Name: "hero-image.jpg"
- Store media.id → featured_image_id
2. Create Post
- Post object:
{
"title": "New Product Launch",
"content": "...",
"featured_media": featured_image_id
}
Common Use Cases
Featured Image Management
- Upload images for use as featured images in posts
- Automatically set featured images during content creation
- Batch upload and assign featured images
Content Media
- Upload images to embed in post content
- Add galleries to posts
- Include downloadable resources (PDFs, documents)
Automated Asset Management
- Upload images from external sources
- Process and upload generated graphics
- Import media from other systems
Bulk Media Upload
- Upload multiple files from a folder
- Migrate media from another CMS
- Batch process and upload images
Dynamic Media Creation
- Generate images programmatically
- Create and upload QR codes
- Generate and upload charts/graphs
Best Practices
- Always use absolute file paths
- Verify file exists before attempting upload
- Use descriptive file names (good for SEO)
- Let WordPress auto-detect content type when possible
- Store the returned media ID for later use
- Check file size before upload
- Optimize images before uploading
- Use appropriate file formats (JPG for photos, PNG for graphics)
- Handle upload errors appropriately
- Clean up local files after successful upload if needed
Image Optimization Tips
Before uploading images:
- Resize to appropriate dimensions
- Compress to reduce file size
- Use appropriate format (JPG, PNG, WebP)
- Strip unnecessary metadata
- Consider using image optimization nodes before upload
Working with Media IDs
After uploading media, use the ID for:
As Featured Image
{
"title": "Post Title",
"content": "Content...",
"featured_media": 789
}
In Post Content
<img src="https://yoursite.com/wp-content/uploads/2024/01/image.jpg" />
In Gallery
{
"gallery_ids": [789, 790, 791]
}
File Path Examples
Windows
C:\\Users\\username\\Pictures\\image.jpg
D:\\Projects\\website\\assets\\logo.png
Linux/Mac
/home/user/images/photo.jpg
/var/data/documents/report.pdf
Relative to Robot
./downloads/image.jpg
../assets/logo.png
Troubleshooting
Error: "File path cannot be empty"
- Ensure File Path input is provided
- Verify the variable contains a valid path
Error: File not found
- Check the file path is correct
- Verify the file exists at that location
- Ensure proper path separators (/ or \)
- Check file permissions
Error: "File name cannot be empty"
- Provide a File Name value
- Include file extension in the name
Upload fails with large files:
- Check WordPress upload size limit (wp-config.php, php.ini)
- Compress or resize the file
- Increase upload limits if you have server access
Wrong content type:
- Use "default" to let WordPress detect
- Ensure content type matches actual file type
- Check WordPress allowed file types
Content Type Selection
When to specify content type:
- Use "default" - For most cases (recommended)
- Specify type - When default detection fails
- Rare cases - WordPress incorrectly identifies the file
Performance Considerations
- Large files take longer to upload
- Image processing (thumbnail generation) adds time
- Multiple uploads should be done sequentially to avoid memory issues
- Consider upload limits and timeouts for very large files
- Network speed affects upload time
Security Considerations
- WordPress validates file types for security
- Some file types are blocked by default (exe, php, etc.)
- SVG files may be restricted due to XSS risks
- Always upload from trusted sources
- Validate file contents before upload
- Use appropriate user permissions
Media Library Organization
After upload:
- Media appears in WordPress Media Library
- Organized by upload date
- Can be categorized using media categories (if plugin installed)
- Searchable by filename
- Can be edited in WordPress admin
Integration Examples
Download and Upload External Image
1. HTTP Request to download image → Save to local file
2. Create Media
- File Path: downloaded file path
- File Name: "external-image.jpg"
3. Store media.id
4. Delete local file (cleanup)
Bulk Upload from Folder
1. List files in folder → Get file list
2. For each file:
- Create Media
- File Path: current file path
- File Name: current file name
- Store media ID and filename mapping
3. Generate upload report
Upload and Embed in Post
1. Create Media → Store media.source_url
2. Build post content with image:
content = `<img src="${media.source_url}" alt="description" />`
3. Create Post with embedded image