3.0 KiB
3.0 KiB
id, title, challengeType, forumTopicId
id | title | challengeType | forumTopicId |
---|---|---|---|
bd7158d8c443edefaeb5bd0f | File Metadata Microservice | 4 | 301506 |
Description
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.
*/