Send image to nodejs server. FromData is always an empty {}

Here’s my code:

const folder = await fs.getTemporaryFolder();
         //list of parent artboards
	let artboardList = [];
	await documentRoot.children.forEach(e => {
		artboardList.push(e);
	});
       //rendering the children to a temp dir
	const artboardChildren = artboardList.filter(node => node instanceof scenegraph.Artboard);
	const arr = await artboardChildren.reduce(async (all, ab) => {
		const currentTask = ab.children.map(async item => {
			const file = await folder.createFile(`${item.guid}.png`, { overwrite: true });
			const obj = {};
			obj.node = item;
			obj.outputFile = file;
			obj.type = 'png';
			obj.scale = 1;
			return obj;
		});
		const current = await Promise.all(currentTask);
		return (await all).concat(current);
	}, []);
	const renditions = await Promise.all(arr);
	await application.createRenditions(renditions);
         //fetching data from children
	const entries = await folder.getEntries();
	const renderedEntries = [];
	const obj = {};
	entries.forEach(entry => {
		for (let i = 0; i < entry.name.length; i++) {
			obj.name = entry.name;
			obj.nativePath = entry.nativePath;
		}
		renderedEntries.push(obj);
	});
// all data is shown as expected
	//console.log(renderedEntries);
	let imagePath = renderedEntries[0];
	const file = {
		uri: imagePath.nativePath,
		name: imagePath.name,
		type: 'png',
	};
       //i want to send some data and the actual to my nodejs endpoint that handles the data using multer.
	let data = new formData();
	data.append('names', 'some name');
	console.log(data); //{}

	// Axios.post('http://localhost:4500/api/upload', { data: formData });
};

console.log will only log iterable objects like arrays. The formData itself might not be actually empty. Try logging out something like data.names

1 Like

Using this snippet

	let data = new FormData();
	data.append('names', 'some name');
	console.log(data.names); //results: undefined