I found the issue
I was naming the file FormDate wrong. It needed to match my field name.
Client-side solution:
formData.append(`images`, file, file.name);
Controller:
'use strict';
/**
* listing controller
*/
const { createCoreController } = require('@strapi/strapi').factories;
module.exports = createCoreController('api::listing.listing', ({ strapi }) => ({
async create(ctx) {
const listing = JSON.parse(ctx.request.body.data);
const files = ctx.request.files;
console.log(listing, files)
// add listing to the database
const entity = await strapi.service('api::listing.listing').create({
data: {
contact_firstname: listing.contact_firstname,
contact_lastname: listing.contact_lastname,
contact_phone: listing.contact_phone,
contact_email: listing.contact_email,
contact_city: listing.contact_city,
contact_state: listing.contact_state,
title: listing.title,
price: listing.price,
description: listing.description,
category: listing.category,
featured: listing.featured,
publishedAt: null,
session_id: session.id,
},
files
});
console.log(entity)
const sanitizedEntity = await this.sanitizeOutput(entity, ctx);
return { id: session.id, sanitizedEntity }
},
}));