2020-09-29 22:09:04 +02:00

3.0 KiB

id, title, challengeType, forumTopicId
id title challengeType forumTopicId
bd7158d8c443edefaeb5bd0f File Metadata Microservice 4 301506

Description

Build a full stack JavaScript app that is functionally similar to this: https://file-metadata.freecodecamp.repl.co/. Working on this project will involve you writing your code on Repl.it on our starter project. After completing this project you can copy your public Repl.it URL (to the homepage of your app) into this screen to test it! Optionally you may choose to write your project on another platform but it must be publicly visible for our testing. Start this project on Repl.it using this link or clone this repository on GitHub! If you use Repl.it, remember to save the link to your project somewhere safe!

Instructions

Tests

tests:
  - text: I can provide my own project, not the example URL.
    testString: "getUserInput => {
      assert(!(new RegExp('.*/file-metadata.freecodecamp.repl.co')).test(getUserInput('url')));
    }"
  - text: I can submit a form that includes a file upload.
    testString: "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\"]'));
    }"
  - text: The form file input field has the <code>name</code> attribute set to <code>upfile</code>.
    testString: "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\"]'));
    }"
  - text: When I submit something, I will receive the file <code>name</code>, <code>type</code>, and <code>size</code> in bytes within the JSON response.
    testString: "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');
    }"

Challenge Seed

Solution

/**
  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.
*/