2018-10-25 20:29:56 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								---
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								id: bd7158d8c443edefaeb5bd0f
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								title: File Metadata Microservice
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								challengeType: 4
							 
						 
					
						
							
								
									
										
										
										
											2019-08-05 09:17:33 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								forumTopicId: 301506
							 
						 
					
						
							
								
									
										
										
										
											2021-01-13 03:31:00 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								dashedName: file-metadata-microservice
							 
						 
					
						
							
								
									
										
										
										
											2018-10-25 20:29:56 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								---
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-11-27 19:02:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# --description--
  
						 
					
						
							
								
									
										
										
										
											2020-09-23 20:21:09 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-11-27 19:02:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Build a full stack JavaScript app that is functionally similar to this: < https: / / file-metadata-microservice . freecodecamp . rocks / > . Working on this project will involve you writing your code using one of the following methods:
							 
						 
					
						
							
								
									
										
										
										
											2020-11-11 14:32:10 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-11-27 19:02:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								-    Clone [this GitHub repo ](https://github.com/freeCodeCamp/boilerplate-project-filemetadata/ ) and complete your project locally. 
						 
					
						
							
								
									
										
										
										
											2021-04-29 06:13:38 -04:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								-    Use [our Replit starter project ](https://replit.com/github/freeCodeCamp/boilerplate-project-filemetadata ) to complete your project. 
						 
					
						
							
								
									
										
										
										
											2020-11-27 19:02:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								-    Use a site builder of your choice to complete the project. Be sure to incorporate all the files from our GitHub repo. 
						 
					
						
							
								
									
										
										
										
											2020-11-11 14:32:10 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-11-24 23:02:34 +05:30 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								When you are done, make sure a working demo of your project is hosted somewhere public. Then submit the URL to it in the `Solution Link`  field. Optionally, also submit a link to your project's source code in the `GitHub Link`  field.
							 
						 
					
						
							
								
									
										
										
										
											2018-10-25 20:29:56 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-11-27 19:02:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# --instructions--
  
						 
					
						
							
								
									
										
										
										
											2018-10-25 20:29:56 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-11-11 14:32:10 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								**HINT:** You can use the `multer`  npm package to handle file uploading.
							 
						 
					
						
							
								
									
										
										
										
											2018-10-25 20:29:56 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-11-27 19:02:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# --hints--
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								You should provide your own project, not the example URL.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```js
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								(getUserInput) => {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  assert(
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    !/.*\/file-metadata-microservice\.freecodecamp\.rocks/.test(
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      getUserInput('url')
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    )
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  );
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								};
							 
						 
					
						
							
								
									
										
										
										
											2018-10-25 20:29:56 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-11-27 19:02:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								You can submit a form that includes a file upload.
							 
						 
					
						
							
								
									
										
										
										
											2018-10-25 20:29:56 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-11-27 19:02:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								```js
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								async (getUserInput) => {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  const site = await fetch(getUserInput('url'));
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  const data = await site.text();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  const doc = new DOMParser().parseFromString(data, 'text/html');
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  assert(doc.querySelector('input[type="file"]'));
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								};
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
									
										
										
										
											2020-09-23 20:21:09 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-11-27 19:02:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								The form file input field has the `name`  attribute set to `upfile` .
							 
						 
					
						
							
								
									
										
										
										
											2018-10-25 20:29:56 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-11-27 19:02:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								```js
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								async (getUserInput) => {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  const site = await fetch(getUserInput('url'));
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  const data = await site.text();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  const doc = new DOMParser().parseFromString(data, 'text/html');
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  assert(doc.querySelector('input[name="upfile"]'));
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								};
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								When you submit a file, you receive the file `name` , `type` , and `size`  in bytes within the JSON response.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```js
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								async (getUserInput) => {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  const formData = new FormData();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  const fileData = await fetch(
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    'https://cdn.freecodecamp.org/weather-icons/01d.png'
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  );
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  const file = await fileData.blob();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  formData.append('upfile', file, 'icon');
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  const data = await fetch(getUserInput('url') + '/api/fileanalyse', {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    method: 'POST',
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    body: formData
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  });
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  const parsed = await data.json();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  assert.property(parsed, 'size');
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  assert.equal(parsed.name, 'icon');
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  assert.equal(parsed.type, 'image/png');
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								};
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
									
										
										
										
											2018-10-25 20:29:56 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-11-27 19:02:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# --solutions--
  
						 
					
						
							
								
									
										
										
										
											2018-10-25 20:29:56 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```js
							 
						 
					
						
							
								
									
										
										
										
											2019-10-24 10:08:13 +05:30 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								/**
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  Backend challenges don't need solutions, 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  because they would need to be tested against a full working project. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  Please check our contributing guidelines to learn more.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*/
							 
						 
					
						
							
								
									
										
										
										
											2018-10-25 20:29:56 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								```