89 lines
2.9 KiB
Markdown
89 lines
2.9 KiB
Markdown
---
|
|
id: bd7158d8c443edefaeb5bd0f
|
|
title: Microservizio Metadati di un file
|
|
challengeType: 4
|
|
forumTopicId: 301506
|
|
dashedName: file-metadata-microservice
|
|
---
|
|
|
|
# --description--
|
|
|
|
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:
|
|
|
|
- Clonare [questa repository GitHub](https://github.com/freeCodeCamp/boilerplate-project-filemetadata/) e completare il tuo progetto localmente.
|
|
- Usare [la nostra bozza di progetto su Replit](https://replit.com/github/freeCodeCamp/boilerplate-project-filemetadata) per completare il tuo progetto.
|
|
- Usare un costruttore di siti di tua scelta per completare il progetto. Assicurati di incorporare tutti i file del nostro repository GitHub.
|
|
|
|
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`.
|
|
|
|
# --instructions--
|
|
|
|
**SUGGERIMENTO:** Puoi usare il pacchetto npm `multer` per gestire il caricamento dei file.
|
|
|
|
# --hints--
|
|
|
|
È necessario fornire il proprio progetto, non l'URL di esempio.
|
|
|
|
```js
|
|
(getUserInput) => {
|
|
assert(
|
|
!/.*\/file-metadata-microservice\.freecodecamp\.rocks/.test(
|
|
getUserInput('url')
|
|
)
|
|
);
|
|
};
|
|
```
|
|
|
|
Puoi inviare un modulo che include un caricamento di file.
|
|
|
|
```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"]'));
|
|
};
|
|
```
|
|
|
|
Il campo di input del file form ha l'attributo `name` impostato su `upfile`.
|
|
|
|
```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"]'));
|
|
};
|
|
```
|
|
|
|
Inviando un file, riceverai il `name`, il `type` e la dimensione (`size`) in byte del file, all'interno della risposta JSON.
|
|
|
|
```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.
|
|
*/
|
|
```
|