So I have a wix collection called userImages, an upload button that uploads images to the page, and a submit button that inserts the image into the wix-collection within the ‘image’ field.
After reading throught the api reference for the afterInsert Hook, I created the hook for the wix collection like so:
import { getJSON, fetch } from 'wix-fetch';
import wixData from 'wix-data';
const BucketName = 'pornilarity-bucket170933-production';
const Key = 'test';
const classifyURL = "https://k4whgc6v7g.execute-api.eu-west-2.amazonaws.com/production/pornilarity/classify"
const uploadURL = "https://k4whgc6v7g.execute-api.eu-west-2.amazonaws.com/production/pornilarity/upload"
export async function userImages_afterInsert(item, context) {
console.log("Image inserted");
let options = {
"method": "PUT",
"headers": {
"Content-Type": "application/json"
},
"body": {
"imageName": item,
"fileContext": context,
}
};
try {
let response = await fetch(uploadURL, options);
if (response.ok) {
return response.json();
}
} catch (err) {
return err;
}
}
However, when I upload an image and click on the submit button, it does not execute this function. I know this because I get no logs output to the console such as the one that says “Image inserted”
My upload button and submit button work correctly too, as I can see the images being inserted in my live wix collection:
Any help would be much appreciated!!!