使用nodejs上传到Digital Ocean空间时出现问题

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

我正在尝试请求将图像上传到 Digital Oceans Spaces,但收到以下错误

Error creating and publishing Instagram media: UnknownEndpoint: Inaccessible host:
ndovu-dev-upload.your-space-region.digitaloceanspaces.com'位于端口
undefined'. This service may not be available in the 
us-east-1'区域。`

尝试在不同的区域创建新的空间,但我遇到了相同的错误。

node.js
1个回答
0
投票

错误消息“UnknownEndpoint: Inaccessible host:novu-dev-upload.your-space-region.digitaloceanspaces.com' at port undefined”表示您的 Node.js 应用程序无法连接到您提供的 DigitalOcean Spaces 端点。以下是排查和解决问题的一些步骤

验证端点 URL 访问密钥和秘密密钥 区域可用性 网络连接 Node.js SDK 版本

代码片段示例(假设您正在使用

@digitalocean/spaces

const doSpaces = require('@digitalocean/spaces');

const spaces = new doSpaces({
  name: 'your-space-name', // Replace with your Space name
  region: 'your-space-region', // Replace with your Space region
  accessKey: 'your-access-key', // Replace with your access key
  secretKey: 'your-secret-key', // Replace with your secret key
});

const uploadParams = {
  Bucket: 'your-space-name', // Replace with your Space name
  Key: 'path/to/your/image.jpg', // Replace with your image path
  Body: fs.createReadStream('path/to/your/image.jpg'), // Replace with your image path
};

spaces.putObject(uploadParams)
  .then((response) => {
    console.log('Image uploaded successfully!', response);
  })
  .catch((error) => {
    console.error('Error uploading image:', error);
  });
© www.soinside.com 2019 - 2024. All rights reserved.