Mapbox 上传 api 不返回 tileset id

问题描述 投票:0回答:0

我正在尝试通过 uploads API 将文件上传到 Mapbox studio 我已经按照所有步骤进行操作,但它没有返回所需的结果,而是返回了这个

这是我的代码。请帮助。

import AWS from "aws-sdk";
import fs from "fs";
import Uploads from "@mapbox/mapbox-sdk/services/uploads.js";
import mapboxgl from "mapbox-gl";

const uploadsClient = new Uploads({
  accessToken:"MAPBOX_ACCESS_TOKEN",
  mapboxgl: mapboxgl,
});

const getCredentials = async () => {
  return await uploadsClient
    .createUploadCredentials()
    .send()
    .then((response) => {
      console.log("log ", response.body);
      return response.body;
    });
};

const putFileOnS3 = (credentials) => {
  const s3 = new AWS.S3({
    accessKeyId: credentials.accessKeyId,
    secretAccessKey: credentials.secretAccessKey,
    sessionToken: credentials.sessionToken,
    region: "us-east-1",
  });
  return s3.putObject(
    {
      Bucket: credentials.bucket,
      Key: credentials.key,
      Body: fs.createReadStream("book1.jpg"),
    },
    (err, data) => {
      if (err) {
        console.log(err);
      } else {
        console.log("fole uploaded success fully", data);
      }
    }
  );
};

getCredentials().then(putFileOnS3);

根据文档,它应该返回此响应:

{
  "complete": false,
  "tileset": "example.markers",
  "error": null,
  "id": "hij456",
  "name": "example-markers",
  "modified": "{timestamp}",
  "created": "{timestamp}",
  "owner": "{username}",
  "progress": 0
}

但我的回答是

{
  ETag: '"3ed1b49aa52ba769138b7770b38cfa6f"',
  ServerSideEncryption: 'AES256',
  VersionId: 'omlUQOXPS77CJo.c8n4h2.LT.nYKblCL'
}
node.js amazon-s3 mapbox aws-sdk mapbox-gl
© www.soinside.com 2019 - 2024. All rights reserved.