2.7 KiB
2.7 KiB
id, title, challengeType, forumTopicId, dashedName
id | title | challengeType | forumTopicId | dashedName |
---|---|---|---|---|
bd7158d8c443edefaeb5bd0f | 文件元數據微服務 | 4 | 301506 | file-metadata-microservice |
--description--
構建一個 JavaScript 的全棧應用,在功能上與這個應用相似:https://file-metadata-microservice.freecodecamp.rocks/。 在這個項目中,你將使用以下方法之一編寫你的代碼:
- 克隆 this GitHub repo 並在本地完成項目。
- 使用我們的 Replit 初始化項目來完成你的項目。
- 使用你選擇的網站生成器來完成項目。 需要包含我們 GitHub 倉庫的所有文件。
完成本項目後,請將一個正常運行的 demo(項目演示)託管在可以公開訪問的平臺。 然後在 Solution Link
字段中提交它的 URL。 此外,還可以將項目的源碼提交到 GitHub Link
中。
--instructions--
** 提示:** 可以使用 multer
npm 包來處理上傳文件
--hints--
提交自己的項目,而不是示例的 URL。
(getUserInput) => {
assert(
!/.*\/file-metadata-microservice\.freecodecamp\.rocks/.test(
getUserInput('url')
)
);
};
可以提交一個包含上傳文件的表單。
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"]'));
};
表單的文件上傳標籤的 name
屬性設置成 upfile
。
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"]'));
};
當提交一個文件時,在 JSON 響應中收到文件的 name
、type
和size
(以 bytes(字節)爲單位)。
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--
/**
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.
*/