Javascript 如何解压Gunzip以及如何将对象解析为Json?

Javascript 如何解压Gunzip以及如何将对象解析为Json?,javascript,node.js,json,Javascript,Node.js,Json,我需要上传个人资料图片到个人资料。我需要获得ID,以便将图片上传到正确的个人资料。API的响应是一个Gunzip对象 .then(resp=>JSON.parse(resp)).then(data=>{console.log(data.Gunzip.read(5)}) 我已经尝试过了,但出现了一个错误:(节点:16100)未处理PromisejectionWarning:SyntaxError:JSON中位置1处的意外标记o const fetch = require("node-fetch")

我需要上传个人资料图片到个人资料。我需要获得ID,以便将图片上传到正确的个人资料。API的响应是一个Gunzip对象

.then(resp=>JSON.parse(resp)).then(data=>{console.log(data.Gunzip.read(5)})

我已经尝试过了,但出现了一个错误:(节点:16100)未处理PromisejectionWarning:SyntaxError:JSON中位置1处的意外标记o

const fetch = require("node-fetch");
const userID = '12345'
const EXAMPLE_PUT_URL = `https://backend.example.com/api/users/${userID}`
const EXAMPLE_GET_URL = `https://backend.example.com/api/users/?limit=5`

const ACCESS_TOKEN = 'NWNmNmYyOWMzNTk5YTA3YjU3MGZkN2Y2OmV6UXo1TiZnXmVtWmJfKzRsOFJ5LWFMLShUUzFzbno7dDNpLV5KX0dOLFIwT1dkTFh1VFZWalE2LFNtKX4pV3U='

var fs = require('fs');

var contents = fs.readFileSync('images/profile1.jpg', 'utf8');

fetch(EXAMPLE_GET_URL, {
    method: 'GET',
    headers: {
      "Authorization": `Basic ${ACCESS_TOKEN}`,
      "Content-type": "application/json",
      "Accept": "application/json",
      "Accept-Charset": "utf-8",
    }, 
  })
    .then(response => { 
          fetch(EXAMPLE_PUT_URL, {
            method: 'PUT',
            headers: {
              "Authorization": `Basic ${ACCESS_TOKEN}`,
              "Content-type": "application/json",
              "Accept": "application/json",
              "Accept-Charset": "utf-8",
            },
            body: JSON.stringify({
                  avatar:contents,
              })      
          })
          console.log(response)})
    ;
使用这段代码,我得到了压缩的对象而不是对象,所以我看不到我需要的ID