Read the body of a Fetch Promise

Notice you're dealing with a Response object. You need to basically read the response stream with Response.json() or Response.text() (or via other methods) in order to see your data. Otherwise your response body will always appear as a locked readable stream. For example:

fetch('https://api.ipify.org?format=json')
.then(response=>response.json())
.then(data=>{ console.log(data); })

If this gives you unexpected results, you may want to inspect your response with Postman.


I had a typo in my code as pointed out by GabeRogan in this comment:

Ok awesome. To be quite honest I have absolutely no clue why you're getting undefined, except that it might be some sort of misspelling error?

Here's my updated code for the front end which returns the response body text:

Client.upload(this.file).then(response => response.text())
  .then((body) => {
    console.log(body);
  });

body is a string that reads Unique File Name: [FILE-NAME]

Here's a good explanation of the Fetch API and reading the response you get from the promise object: Css tricks: Using Fetch.


You can also use async/await:

When returning json content:

Client.upload(this.file).then(async r => console.log(await r.json()))

or just returning in textual form:

Client.upload(this.file).then(async r => console.log(await r.text()))