We built this function as we were looking to prototype the use of GPTs and AI Image generators to create images tuned to their purpose. For example, images in a list should help click-through rates, and images shown as the main headers of an article should support the content of that article and deepen engagement.
For this, we needed an easy way to update image fields using, in our case, make.com as our automation platform. This solution will work equally well with other automation platforms like n8n or Zapier.
You can get the full function here:
https://github.com/MCTO-the-dig/wix/blob/main/uploadImageToItem.js
We needed a simple way of āpushingā these image updates into a field in a Wix collection item. As in the example scenario below, which reacts to an image file upload and then loads it to the right field and collection in Wix

There are two parts to getting this function working.
š ļøStep 1: AddĀ the code to backend/http-functions.js
This file creates a secure HTTP endpoint that allows uploading images to a Wix collection from external tools (like Make.com) using public image URLs.
Make sure you add the authorisation function to your http-functions.js if you have not already done so.
The code is below for convenience. How it works is fully documented here:
https://github.com/MCTO-the-dig/wix/blob/main/codeToUpdateAnyField
which has a similar function focused on updating data fields.
Add a secret to Wix Secret if you have not already done so
Use the first part of the code from https://github.com/MCTO-the-dig/wix/blob/main/uploadImageToItem.js
And paste it into your - backend/http-functions.jsĀ - file on your Wix site.

And when you have pasted the code, it should look something like this

āļøStep 2: Add the code below to your backend/events.jsĀ file
This is the automatic follow-up handler. When the image is successfully uploaded to the Media Manager, this function gets triggered and updates the related item in your collection. It is effectively where the main work happens.
It is clearly marked, and you can lift it from here:
https://github.com/MCTO-the-dig/wix/blob/main/uploadImageToItem.js
It will look something like this:

šFinal Step: Using the function
Use Case:Ā Upload an image via a URL from Make.comĀ (or similar) and automatically update a Wix database itemās image field.
Security:Ā Uses a secret key stored in Wix Secrets Manager to authorise requests.
To use this function, all you need to do is send an HTTP request containing a public URL of the image, and it will do the rest. Below is the example set up in make.com
From Make.com or any system, send a POSTĀ request to:
https://your-wix-site.com/_functions/uploadImageToItem
Understanding the base URL for your use case is documented here:
https://dev.wix.com/docs/velo/velo-only-apis/wix-http-functions/wix-http-function-request/base-url
With the headers:
and body:
Ā š IMPORTANT Field Mapping: Make sure you prefix your Field ID with image_
