Can't successfully upload a file to an existing entry from Node JS

@jbm I had the exact same problem I was able to implement this using the upload service using the following code

const fileStat = fs.statSync(filepath);
const attachment = await strapi.plugins.upload.services.upload.upload({
	data: {
		refId: result.id,
		ref: 'my-collection',
		field: 'attachments',
	},
	files: {
		path: filepath,
		name: `filename.pdf`,
		type: 'application/pdf', // mime type
		size: fileStat.size,
	},
});
9 Likes