Submit data into wix database and handle it using afterInsert Hook

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!!!

I don´t understand your problem. You state your images are being inserted correctly, just that you don´t see the console.log. But data.js is a backend function and backend functions do not show console.log inside the browser console (but they do inside Wix Editor). So could be more specific?

You can also use Site monitoring or stackdriver to track backend events.

Ahh i see, so how do I see the logs within the wix editor? I just want to make sure that this function is actually getting triggered upon submit

Ok I will give it a try. Thank you