Files

2.7 KiB
Raw Permalink Blame History

id, title, challengeType, forumTopicId, dashedName
id title challengeType forumTopicId dashedName
bd7158d8c443edefaeb5bd0f 文件元数据微服务 4 301506 file-metadata-microservice

--description--

构建一个 JavaScript 的全栈应用,在功能上与这个应用相似:https://file-metadata-microservice.freecodecamp.rocks/。 在这个项目中,你将使用以下方法之一编写你的代码:

完成本项目后,请将一个正常运行的 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 响应中收到文件的 nametypesize(以 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.
*/