TryGhost / Zapier

Ghost <-> Zapier Integration
https://developer.zapier.com/app/1566
MIT License
5 stars 3 forks source link

Featured Image field is saving Zapier's hydration pointer uri, not uploading image #55

Closed hwlmatt closed 2 years ago

hwlmatt commented 2 years ago

Expected Behavior

Featured Image field uploads the selected image to Ghost

Actual Behavior

The Featured Image field is not uploading an image file passed to it, but rather saving the uri reference pointer (the stashFile like in this example created during a previous step's hydrator (download from external source to zapier). This results in site images being served from Zapier's stashfile url.

Steps to Reproduce

Possible Cause

Cause Line 99 of create_post.js {key: 'feature_image', required: false},

is missing `type: 'file' Ghost's createPost function is not handling dehydration.

So I think this is just passing along that pointer uri as a text string.

That uri gets saved on the site's end, and loaded on the frontend as an externally hosted image. But that uri is intended to be passed and dehydrated, not as a permanent uri of a file.

Possible Fix

[ UPDATE: see comment below with links to gists. I have uploads working in a clone of this now.] Handling multiple passed files and only uploading uniques, and getting the string back from Ghost api to pass with the rest of the createPost form.

Optional: Could add a dehydrateFile method to createPost's res if you wish to make the Ghost uploaded image available to future Zap steps. Thought this doesn't seem necessary.

Sorry I couldn't be more help with a PR or something, I'm not where I can setup anything to test, etc. Happy to do a PR if the gists in my later comment look up to standards.

Reference docs

This is an example of an upload hydration/dehydration: https://github.com/codebycaleb/zapier-hydration-example/blob/master/creates/uploadFile.js

Zapier's cli docs on hydration/dehydration

hwlmatt commented 2 years ago

I have a version of this working in a test zap now.

All images on form: app/lib/upload_image.js (gist)

This is handling all image fields (featured_image, twitter_image, and og_image) and only uploading unique files. It uses the same upload response for fields sharing the same file pointer (Zapier "stash file"). Added this file to /lib/, and made create_post() async. The edited create_post() is on the same gist here.

It basically does the following:

From there the create_post() operates as is.

Happy to PR if it meets the coding standards/requirements, etc.

ONLY featured_image upload: app/lib/upload_featured_image.js (gist)

This is where I started on this. Just handles the feature_image upload. Added this file to /lib/, and made create_post() async. The edited create_post() is on the same gist here.

naz commented 2 years ago

Hey @hwlmatt the PR where we could discuss and see the differences would be much appreciated. Some comments on the approach you've taken:

There have not been reports about this issue ever since the initial report. I'll close it out for now and very happy to reopen and let @royalfig to give a hand if there's interest in fixing this bug.