source/middleware/file upload.js
async function upload_file(file, { upload_folder, log })
{
	if (log)
	{
		log.debug(`Uploading: ${file.filename}`)
	}

	// Generate random unique filename
	const file_name = await generate_unique_filename(upload_folder,
	{
		on_collision: (file_name) =>
		{
			log.info(`Generate unique file name: collision for "${file_name}". Taking another try.`)
		}
	})

	// dot_extension: path.extname(file.filename)

	const output_file = path.join(upload_folder, file_name)

	// Write the file to disk
	return await new Promise((resolve, reject) =>
	{
		// Ensure the `upload_folder` exists
		// (just an extra precaution)
		fs.ensureDir(upload_folder, (error) =>
		{
			if (error)
			{
				return reject(error)
			}

			// Open output file stream
			const stream = fs.createWriteStream(output_file)

			// Pipe file contents to disk
			file.pipe(stream)
				.on('finish', () => resolve(path.relative(upload_folder, output_file)))
				.on('error', error => reject(error))
		})
	})
}
async function upload_file(file, { upload_folder, log })
{
	if (log)
	{
		log.debug(`Uploading: ${file.filename}`)
	}

	// Generate random unique filename
	const file_name = await generate_unique_filename(upload_folder,
	{
		on_collision: (file_name) =>
		{
			log.info(`Generate unique file name: collision for "${file_name}". Taking another try.`)
		}
	})

	// dot_extension: path.extname(file.filename)

	const output_file = path.join(upload_folder, file_name)

	// Write the file to disk
	return await new Promise((resolve, reject) =>
	{
		// Ensure the `upload_folder` exists
		// (just an extra precaution)
		fs.ensureDir(upload_folder, (error) =>
		{
			if (error)
			{
				return reject(error)
			}

			// Open output file stream
			const stream = fs.createWriteStream(output_file)

			// Pipe file contents to disk
			file.pipe(stream)
				.on('finish', () => resolve(path.relative(upload_folder, output_file)))
				.on('error', error => reject(error))
		})
	})
}
async function upload_file ( file , { upload_folder , log } ) { if ( log ) { log . debug ( ` ${ file . filename } ` ) } // Generate random unique filename const file_name = await generate_unique_filename ( upload_folder , { on_collision : ( file_name ) => { log . info ( ` ${ file_name } ` ) } } ) // dot_extension: path.extname(file.filename) const output_file = path . join ( upload_folder , file_name ) // Write the file to disk return await new Promise ( ( resolve , reject ) => { // Ensure the `upload_folder` exists // (just an extra precaution) fs . ensureDir ( upload_folder , ( error ) => { if ( error ) { return reject ( error ) } // Open output file stream const stream = fs . createWriteStream ( output_file ) // Pipe file contents to disk file . pipe ( stream ) . on ( 'finish' , ( ) => resolve ( path . relative ( upload_folder , output_file ) ) ) . on ( 'error' , error => reject ( error ) ) } ) } ) }
Handles file upload. Takes a `file` busboy file object along with `upload_folder` option. Writes the `file` stream to `upload_folder` naming it with a randomly generated filename.  Returns a Promise resolving to the randomly generated filename.
Handles file upload . Takes a file busboy file object along with upload_folder option . Writes the file stream to upload_folder naming it with a randomly generated filename . Returns a Promise resolving to the randomly generated filename .