src/utilities/http.js
function POST_FILE(uri, params, filepath) {
	var form = new FormData();

	for (var i in params) {
		form.append(i, params[i]);
	}

	let contenttype = 'INVALID';

	if(filepath.split('.').pop().toLowerCase() == 'jpg') { contenttype = 'image/jpg' }
	if(filepath.split('.').pop().toLowerCase() == 'png') { contenttype = 'image/png' }
	if(filepath.split('.').pop().toLowerCase() == 'gif') { contenttype = 'image/gif' }

	if(contenttype == 'INVALID') { throw 'Invalid image type.' }

	let imageData = fs.readFileSync(filepath);

	form.append('image', imageData, {
		filename: filepath.split('/').pop(),
		filepath: filepath,
		contentType: contenttype,
		knownLength: imageData.length
	});

	const requestURL = `${uri}`;
	log(`request URL: ${requestURL}`);

	return fetch(requestURL, { method: 'POST', compress: compress, body: form, headers: { 'Content-Type': 'multipart/form-data; boundary='+form.getBoundary() } })
    .then(function handleRequest(res) {
			const status = res.status;
			if (status != 200) {
				const error = new Error(`Request failed: ${status}`);
				error.status = status;
				throw error;
			}
			return res.json();
		})
		.catch(error => {
			log(`error: ${error}`);
			throw error;
		});
}
function POST_FILE(uri, params, filepath) {
	var form = new FormData();

	for (var i in params) {
		form.append(i, params[i]);
	}

	let contenttype = 'INVALID';

	if(filepath.split('.').pop().toLowerCase() == 'jpg') { contenttype = 'image/jpg' }
	if(filepath.split('.').pop().toLowerCase() == 'png') { contenttype = 'image/png' }
	if(filepath.split('.').pop().toLowerCase() == 'gif') { contenttype = 'image/gif' }

	if(contenttype == 'INVALID') { throw 'Invalid image type.' }

	let imageData = fs.readFileSync(filepath);

	form.append('image', imageData, {
		filename: filepath.split('/').pop(),
		filepath: filepath,
		contentType: contenttype,
		knownLength: imageData.length
	});

	const requestURL = `${uri}`;
	log(`request URL: ${requestURL}`);

	return fetch(requestURL, { method: 'POST', compress: compress, body: form, headers: { 'Content-Type': 'multipart/form-data; boundary='+form.getBoundary() } })
    .then(function handleRequest(res) {
			const status = res.status;
			if (status != 200) {
				const error = new Error(`Request failed: ${status}`);
				error.status = status;
				throw error;
			}
			return res.json();
		})
		.catch(error => {
			log(`error: ${error}`);
			throw error;
		});
}
function POST_FILE ( uri , params , filepath ) { var form = new FormData ( ) ; for ( var i in params ) { form . append ( i , params [ i ] ) ; } let contenttype = 'INVALID' ; if ( filepath . split ( '.' ) . pop ( ) . toLowerCase ( ) == 'jpg' ) { contenttype = 'image/jpg' } if ( filepath . split ( '.' ) . pop ( ) . toLowerCase ( ) == 'png' ) { contenttype = 'image/png' } if ( filepath . split ( '.' ) . pop ( ) . toLowerCase ( ) == 'gif' ) { contenttype = 'image/gif' } if ( contenttype == 'INVALID' ) { throw 'Invalid image type.' } let imageData = fs . readFileSync ( filepath ) ; form . append ( 'image' , imageData , { filename : filepath . split ( '/' ) . pop ( ) , filepath : filepath , contentType : contenttype , knownLength : imageData . length } ) ; const requestURL = ` ${ uri } ` ; log ( ` ${ requestURL } ` ) ; return fetch ( requestURL , { method : 'POST' , compress : compress , body : form , headers : { 'Content-Type' : 'multipart/form-data; boundary=' + form . getBoundary ( ) } } ) . then ( function handleRequest ( res ) { const status = res . status ; if ( status != 200 ) { const error = new Error ( ` ${ status } ` ) ; error . status = status ; throw error ; } return res . json ( ) ; } ) . catch ( error => { log ( ` ${ error } ` ) ; throw error ; } ) ; }
For posting a file using multipart formdata

@param {any} uri - request URL
@param {any} params - request parameters
@param {any} filepath - path to the file
@returns
For posting a file using multipart formdata