2021-06-15 00:49:18 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								---
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								id: bd7158d8c443edefaeb5bd0f
							 
						 
					
						
							
								
									
										
										
										
											2021-07-09 21:23:54 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								title: Microservizio Metadati di un file
							 
						 
					
						
							
								
									
										
										
										
											2021-06-15 00:49:18 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								challengeType: 4
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								forumTopicId: 301506
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								dashedName: file-metadata-microservice
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								---
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# --description--
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-07-09 21:23:54 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Costruisci un'app JavaScript full-stack che sia funzionalmente simile a questa: < https: / / file-metadata-microservice . freecodecamp . rocks / > . Lavorare su questo progetto ti porterà a scrivere il tuo codice utilizzando uno dei seguenti metodi:
							 
						 
					
						
							
								
									
										
										
										
											2021-06-15 00:49:18 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-07-09 21:23:54 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								-    Clonare [questa repository GitHub ](https://github.com/freeCodeCamp/boilerplate-project-filemetadata/ ) e completare il tuo progetto localmente. 
						 
					
						
							
								
									
										
										
										
											2021-07-19 16:05:37 +05:30 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								-    Usare [la nostra bozza di progetto su Replit ](https://replit.com/github/freeCodeCamp/boilerplate-project-filemetadata ) per completare il tuo progetto. 
						 
					
						
							
								
									
										
										
										
											2021-08-25 09:12:11 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								-    Usare un costruttore di siti di tua scelta per completare il progetto. Assicurati di incorporare tutti i file del nostro repository GitHub. 
						 
					
						
							
								
									
										
										
										
											2021-06-15 00:49:18 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2022-01-02 16:26:15 +05:30 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Quando hai finito, assicurati che una demo funzionante del tuo progetto sia ospitata in qualche percorso pubblico. Quindi invia l'URL nel campo `Solution Link` . Facoltativamente, invia anche un link al codice sorgente del tuo progetto nel campo `GitHub Link` .
							 
						 
					
						
							
								
									
										
										
										
											2021-06-15 00:49:18 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# --instructions--
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-07-09 21:23:54 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								**SUGGERIMENTO:** Puoi usare il pacchetto npm `multer`  per gestire il caricamento dei file.
							 
						 
					
						
							
								
									
										
										
										
											2021-06-15 00:49:18 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# --hints--
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-07-09 21:23:54 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								È necessario fornire il proprio progetto, non l'URL di esempio.
							 
						 
					
						
							
								
									
										
										
										
											2021-06-15 00:49:18 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```js
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								(getUserInput) => {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  assert(
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    !/.*\/file-metadata-microservice\.freecodecamp\.rocks/.test(
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      getUserInput('url')
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    )
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  );
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								};
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-07-09 21:23:54 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Puoi inviare un modulo che include un caricamento di file.
							 
						 
					
						
							
								
									
										
										
										
											2021-06-15 00:49:18 -07: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"]'));
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								};
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-07-09 21:23:54 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Il campo di input del file form ha l'attributo `name`  impostato su `upfile` .
							 
						 
					
						
							
								
									
										
										
										
											2021-06-15 00:49:18 -07: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"]'));
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								};
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-07-09 21:23:54 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Inviando un file, riceverai il `name` , il `type`  e la dimensione (`size` ) in byte del file, all'interno della risposta JSON.
							 
						 
					
						
							
								
									
										
										
										
											2021-06-15 00:49:18 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```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');
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								};
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# --solutions--
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```js
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								/**
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  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.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								*/
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```