BTW this feature has always been a struggle, for platforms. Pabbly for example doesn’t have it, and it took Zapier quiet a while to have it working. I would be a great addition though to have
Unfortunately it didn’t work for me. I’ve used the default “Create Post” functionality with the the image URL in Base64 as suggested above. The result is that a post is created which is expected but there is no featured image ID populated when creating adding the image like this. Neither without using Base64.
STEP #2 - Replace this piece with whichever you want to get your file, I have used Stability AI to generate an Image
STEP #3 - We’re generating Base64 of the file data, Update the value of File field to include your own document data/url. Leave everything else as it is.
Piece #4 - Custom code block - This is where magic happens
Edit the code block piece code and replace the values of username, password and wordpress URL fields - Look at the line numbers 2,3 and 4 for reference.
Can we change the file name?
For example this “wp-content/uploads/2024/02/file_1708079485405.png”
can we change it to “wp-content/uploads/2024/02/file_supercat.png”
In flow Step #44. Upload to WordPress, We’re passing values like title, fileType, description, etc… Add a new field fileName and pass in your file name as value, example
"fileName": "myfilename.png"
In the code block code, Open the code editor and search for
Hi @IOBLR. First, thank you for this addition. Works great without any issues. I need to use the image helper to resize the image so it is less than 3 Mb, then use the file helper to convert. Extra step, but again, great addition and thankful for sharing this. I am running into an issue, and I suspect it’s me not knowing coding. I implemented the change, so I could have a file name, name versus the file_date…. Everything works as expected, but I get the code string as the file name and not the name I entered in the query string on line 37. Is there another change or reference I need to make, so the file name gets populated correctly.
I noticed if I do not reference the extension, it still uploads a file, but it is a non reference file, but the name is there. Basically a file with no associated extension.
If you want to place a dynamic variable inside a string, you have to ${} (dollar sign and curly braces), Only then its value will be dynamically replaced.
Example: If we’re using the code you currently have and if you are passing fileName as ‘cat’
Then the actual value of variable fileName inside the code block will be inputs.fileName.png
Only the fileExtension got replaced as that is inside ${}
With the code I have provided, it will be cat.png because inputs.fileName is inside ${}
You can also take this a step further and do the following
You also mentioned you have to resize the image due to its size, You can update your WordPress file upload config and change MAX_FILE_SIZE to 20 MB or 100 MB to overcome this.
However I don’t think you should serve images of size greater than 500KB - 1MB, It would be better if you make use of CDNs.
@IOBLR Thank you again for the guidance on this. I figured it was something simple. Just did not realize I needed to enclose. Learnng (baby steps). Also, the file size restriction, yes, I agree and will more than likely leave as is. However, the file size issue (at least for me), is when I use the image helper or the file helper piece, and the generate image, or doc is greater than 2 Mb. it throws the “network disconnection” error and you have to refresh the page when converting. Not sure if it is the best method as a work around for this, but when I resize the generated image from Dalle, to 850x850 the actual file size is reduced from 3 Mb to under 2Mb and the piece flows with no errors. However, if i try to run either piece Image or File Helper pieces, without resizing first, I get that error and have to refresh the page, which no result will be provided. Is there a better work around for this?
I’ve made it simpler. I use the existing function to “create a new WordPress post,” through which I can upload the image with the existing piece, and then I delete the post again via the API.
@Gio thank you sharing, I honestly did not think of doing that, however, the question I have… why upload the image if not going to use it in the post you created? Yes, you now have the image on the server, but the automation is to associate the image to the post for future use. At least for me… I guess there are different use cases… . Will remember this one…
@IOBLR i just noticed that I get 2 of the same generated image uploaded. 1 is named as expected, the 2nd image is named with the same name but now with a -1 in the name, but it is not referenced, just uploaded. It works fine when testing, only 1 image uploaded, but when flow runs normally, 2 are uploaded. With or without using loop for the post generation. I have a loop the runs for 2 heading titles in a request that is after image generation and upload. Just curious, does the loop function include all steps above or just the value of the piece in the settings? Can the script be limited to only upload 1 image?
Hi @IOBLR I am thinking the samething in that for some reason my loop is also running the upload twice. Just not sure where it is being called? I exported, but not sure how to upload the file? It gives me an error. Attaching the screen shots of the flow. I removed the loop just now and tested again, and it uploaded 2 images…. Step 6 is where it uploads to WP. This is the new flow.