我正在尝试从浏览器将图像上传到数字海洋空间。这些图像应该是公开的。我能够成功上传图像。
然而,虽然ACL设置为public-read,但上传的文件始终是私有的。
我知道它们是私有的,因为 a) 仪表板显示权限是“私有”,b) 因为公共 URL 不起作用,c) 在仪表板中手动将权限更改为“公共”可以修复所有问题。
这是我正在使用的总体流程。
有什么想法为什么这些图像不公开吗?
以下示例以 TypeScript 编写并使用 AWS 的 v3 SDK。
这会生成用于上传文件的预签名 URL。
import { S3Client, PutObjectCommand } from '@aws-sdk/client-s3'
import { getSignedUrl } from '@aws-sdk/s3-request-presigner'
const client = new S3Client({
region: 'nyc3',
endpoint: 'https://nyc3.digitaloceanspaces.com',
credentials: {
accessKeyId: process.env.DIGITAL_OCEAN_SPACES_KEY,
secretAccessKey: process.env.DIGITAL_OCEAN_SPACES_SECRET,
},
})
const command = new PutObjectCommand({
ACL: 'public-read',
Bucket: 'bucket-name',
Key: fileName,
ContentType: mime,
})
const url = await …Run Code Online (Sandbox Code Playgroud) I'm trying to use the AWS v2 SDK for Go to list all objects in a given bucket on DigitalOcean Spaces. Their documentation gives examples of how to use the v1 SDK to do this, but my app uses v2. I know I could technically use both, but I'd rather not if possible.
Here's what I've got so far:
package main
import (
"context"
"fmt"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/s3"
)
func main() {
customResolver := aws.EndpointResolverWithOptionsFunc(func(service, region string, options ...interface{}) …Run Code Online (Sandbox Code Playgroud) 我在网上看到很多人都遇到了这个问题,现在我自己也遇到了这个问题。我正在尝试使用 boto3 来 list_buckets 在 DigitalOcean Spaces 中。它返回 200 状态代码,但内部没有列出存储桶。奇怪的是,我可以通过代码创建一个存储桶,但我无法列出它。
人们报告说,当他们使用不同的端点 URL 时,他们取得了成功。我使用过以下内容:
https://<space_name>.nyc3.digitaloceanspaces.comhttps://nyc3.digitaloceanspaces.com他们两个都没有运气。
import boto3
s3 = boto3.client('s3', region_name=region, endpoint_url=endpoint, aws_access_key_id=access_id, aws_secret_access_key=secret_key)
s3.list_buckets()
Run Code Online (Sandbox Code Playgroud)
list_buckets返回以下响应。
{'ResponseMetadata': {'RequestId': 'tx00000000000010c9ce0be-0061b571d4-1800930a-nyc3c', 'HostId': '', 'HTTPStatusCode': 200, 'HTTPHeaders': {'transfer-encoding': 'chunked', 'x-amz-request-id': 'tx00000000000010c9ce0be-0061b571d4-1800930a-nyc3c', 'content-type': 'application/xml', 'date': 'Sun, 12 Dec 2021 03:51:48 GMT', 'strict-transport-security': 'max-age=15552000; includeSubDomains; preload'}, 'RetryAttempts': 0}}
我正在本地的 Express 中创建 Shopify 应用程序并收到此错误。当我在服务器上使用此应用程序时,相同的代码正在运行。我不知道为什么这在本地环境中不起作用。
\n我正在使用 Digital Ocean Spaces、Node.js v17.0.1、@aws-sdk/client-s3 v3.171.0。
\nimport { S3 } from "@aws-sdk/client-s3";\nimport dotenv from "dotenv";\n\ndotenv.config();\n\nconst s3Client = new S3({\n endpoint: process.env.SPACES_ENDPOINT,\n region: process.env.SPACES_REGION,\n credentials: {\n accessKeyId: process.env.SPACES_KEY,\n secretAccessKey: process.env.SPACES_SECRET,\n },\n});\n\nexport default s3Client;\nRun Code Online (Sandbox Code Playgroud)\n我已经在 .env 文件中放置了有效的环境变量。
\n\nburhan@burhan:/shopifynode$ shopify app serve\n\xe2\x9c\x93 ngrok tunnel running at https://ebb6-2401-4900-1c02-5a90-982c-9e83-1b5e-b9ee.ngrok.io, with account testmail@mail.com\n\xe2\x9c\x93 .env saved to project root\n\n\xe2\xad\x91 To install and start using your app, open this URL in your browser:\nhttps://ebb6-2401-4900-1c02-5a90-982c-9e83-1b5e-b9ee.ngrok.io/login?shop=my-app-staging.myshopify.com\n\nRunning server\xe2\x80\xa6\n\n> dev\n> cross-env NODE_ENV=development …Run Code Online (Sandbox Code Playgroud) express shopify-app serverless digital-ocean-spaces aws-s3-client
System error occurred
The path of a URI with an authority must start with a slash "/" or be empty.
Automagically fixing the URI by adding a leading slash to the path is
deprecated since version 1.4 and will throw an exception instead.
line#755 file: /home/mySite/www/vendor/guzzlehttp/psr7/src/Uri.php
PHP version: 7.4.14
Error executing "PutObject" on "//mySite.nyc3.digitaloceanspaces.com/mySite.nyc3.digitaloceanspaces.com";
AWS HTTP error:
Server error:
PUT http://mySite.nyc3.digitaloceanspaces.com/mySite.nyc3.digitaloceanspaces.com
resulted in a `501 Not Implemented` response:
<?xml version="1.0" encoding="UTF-8"?>
<Error>
<Code>NotImplemented</Code>
<RequestId>tx00000000000000c12754f-0060564e57-96 (truncated...)
NotImplemented (server):
<?xml version="1.0" encoding="UTF-8"?> …Run Code Online (Sandbox Code Playgroud) InvalidArgument: null
at Request.extractError (P:\Upwork\MyProject\backend\node_modules\aws-sdk\lib\services\s3.js:700:35)
at Request.callListeners (P:\Upwork\MyProject\backend\node_modules\aws-sdk\lib\sequential_executor.js:106:20)
at Request.emit (P:\Upwork\MyProject\backend\node_modules\aws-sdk\lib\sequential_executor.js:78:10)
at Request.emit (P:\Upwork\MyProject\backend\node_modules\aws-sdk\lib\request.js:688:14)
at Request.transition (P:\Upwork\MyProject\backend\node_modules\aws-sdk\lib\request.js:22:10)
at AcceptorStateMachine.runTo (P:\Upwork\MyProject\backend\node_modules\aws-sdk\lib\state_machine.js:14:12)
at P:\Upwork\MyProject\backend\node_modules\aws-sdk\lib\state_machine.js:26:10
at Request.<anonymous> (P:\Upwork\MyProject\backend\node_modules\aws-sdk\lib\request.js:38:9)
at Request.<anonymous> (P:\Upwork\MyProject\backend\node_modules\aws-sdk\lib\request.js:690:12)
at Request.callListeners (P:\Upwork\MyProject\backend\node_modules\aws-sdk\lib\sequential_executor.js:116:18) {
code: 'InvalidArgument',
region: null,
time: 2020-12-31T15:39:45.724Z,
requestId: '',
extendedRequestId: undefined,
cfId: undefined,
statusCode: 400,
retryable: false,
retryDelay: 85.1667642693943
}
Run Code Online (Sandbox Code Playgroud)
尝试上传到 DigitalOcean Spaces 或 Amazon S3 时会出现此错误。
错误消息非常模糊,只是提供了InvalidArgument一个原因。
amazon-s3 amazon-web-services node.js digital-ocean digital-ocean-spaces
我想以编程方式将文件从 Digital Ocean Storage 迁移到 Google Cloud Storage,而不使用 rclone。
我知道驻留在数字海洋存储 (DOS) 中的确切位置文件,并且我有 Google 云存储 (GCS) 的签名 URL。
如何修改以下代码,以便将 DOS 文件直接复制到 GCS 中,而无需中间下载到我的计算机?
def upload_to_gcs_bucket(blob_name, path_to_file, bucket_name):
""" Upload data to a bucket"""
# Explicitly use service account credentials by specifying the private key
# file.
storage_client = storage.Client.from_service_account_json(
'creds.json')
#print(buckets = list(storage_client.list_buckets())
bucket = storage_client.get_bucket(bucket_name)
blob = bucket.blob(blob_name)
blob.upload_from_filename(path_to_file)
#returns a public url
return blob.public_url
Run Code Online (Sandbox Code Playgroud) python google-cloud-storage digital-ocean google-cloud-platform digital-ocean-spaces
amazon-s3 ×4
aws-sdk ×1
aws-sdk-go ×1
boto3 ×1
cors ×1
express ×1
go ×1
node.js ×1
php ×1
python ×1
serverless ×1
shopify-app ×1