【发布时间】:2018-07-01 02:11:08
【问题描述】:
当我这样做时:
foreach ($f in (Get-ChildItem -filter "*.flv")){
Write-S3Object -BucketName bucket.example -File $f.fullName -Key $f.name -CannedACLName PublicRead
}
我收到此错误:
Write-S3Object :
At line:1 char:51
+ foreach ($f in (Get-ChildItem -filter "*.flv")){ Write-S3Object -BucketName xx. ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (Amazon.PowerShe...eS3ObjectCmdlet:WriteS3ObjectCmdlet) [Write-S3Objec
t], InvalidOperationException
+ FullyQualifiedErrorId : Amazon.S3.AmazonS3Exception,Amazon.PowerShell.Cmdlets.S3.WriteS3ObjectCmdlet
我做错了什么?我可以做些什么来查看更多错误,还是这只是语法问题?
如何使用 powershell 将所有特定文件类型上传到存储桶?
编辑:
我故意将Set-DefaultAWSRegion 设置为存储桶不在的区域,然后得到了
Write-S3Object : The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.
正如预期的那样,作为错误消息,因此它看起来可以连接到存储桶并且它知道它不在某个区域中。
另外,如果我在存储桶名称前输入 s3:// 前缀,我会收到一条消息,提示找不到存储桶,所以看起来我现在输入的内容是正确的。
我可以执行 Get-S3Bucket 并查看我帐户中的所有存储桶,因此我知道它已正确配置。
编辑2:
如果我这样做:
> $f = Get-ChildItem -filter "*.flv"
> Write-S3Object
cmdlet Write-S3Object at command pipeline position 1
Supply values for the following parameters:
BucketName: bucket.name
Key: $f[0].name
File: $f[0].fullName
Write-S3Object : The file indicated by the FilePath property does not exist!
At line:1 char:1
+ Write-S3Object
+ ~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (Amazon.PowerShe...eS3ObjectCmdlet:WriteS3ObjectCmdlet) [Write-S3Objec
t], InvalidOperationException
+ FullyQualifiedErrorId : System.ArgumentException,Amazon.PowerShell.Cmdlets.S3.WriteS3ObjectCmdlet
如果我单独执行$f[0].fullName,我将获得对象的完整路径。
但是,这里面有空格。这会是个问题吗?
【问题讨论】:
-
一切看起来都很好,除了 -BucketName 参数。这是你必须在 S3 中设置的东西吗?
-
@TimFerrill
bucket.name就是一个例子。它实际上是实际的存储桶名称,减去s3://前缀。 -
此语句的另一个问题(发生在我身上)是 CannedACLName 选项。在文档中,它以“-CannedACLName PublicRead”的形式提供,但这会导致与上述相同的错误。它需要读取“-CannedACLName public-read”。
标签: powershell amazon-web-services amazon-s3 aws-powershell