Read the body of a Fetch Promise

前端 未结 3 1184
没有蜡笔的小新
没有蜡笔的小新 2020-12-04 21:15

I\'m sure this has a simple answer, but for the life of me I can\'t figure out how to do it.

I have the following express endpoint for uploading to Google Cloud sto

3条回答
  •  长情又很酷
    2020-12-04 21:42

    @GabeRogan gave me the answer (and I had a typo, as expected)

    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]"

    EDIT:

    Here's a good explanation of the Fetch API and reading the response you get from the promise object: https://css-tricks.com/using-fetch/

提交回复
热议问题