Then because I simply want to upload it to my WordPress blog (I have no separate CDN for images), I attempted to use the “Post to WordPress” action. Which I only just discovered can upload media, along with posts and pages.
And just like when you upload a new post using that action, the result is the URL of the uploaded post/page/media.
Although the URL that was returned wasn’t exactly the one I was looking for. I was expecting the absolute URL for the image that was uploaded. But instead, it was the URL of a kind of “preview” page, which is essentially the same template used for a blog post, except the content is the image that was uploaded.
The pages that Chris is referring to are attachment pages — they use a page template similar to posts or pages, but are used to display a single piece of media uploaded to WordPress’ media library. It is a bit odd that this is the link that the Shortcut outputs when uploading a media file, though, it would be nice if it gave you a direct link to the file instead.
I came across this issue a year or two ago when I was first building my image uploading shortcut, which was with the Workflow app at the time. Chris’ solution is quite elegant, but unfortunately, it won’t work for my site. I actually setup my attachment pages to automatically redirect to the image’s corresponding post or to my site’s homepage (if a related post can’t be found).
Instead of grabbing the image URL from the resulting attachment page, I have my shortcut take the file name and rebuild the direct URL since it’s a predictable URL structure.