Hou*_*man 8 powershell amazon-s3 amazon-web-services aws-powershell
当我这样做:
foreach ($f in (Get-ChildItem -filter "*.flv")){
Write-S3Object -BucketName bucket.example -File $f.fullName -Key $f.name -CannedACLName PublicRead
}
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
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
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?有什么我可以做的来看到更多的错误,或者这只是一个语法问题?
如何使用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.
Run Code Online (Sandbox Code Playgroud)
作为一个错误消息,正如预期的那样,所以看起来它可以连接到存储桶,它知道它不在某个区域.
此外,如果我s3://在存储桶名称前输入 前缀,我会收到一条消息,指出无法找到存储桶,因此看起来我现在输入的内容是正确的.
我可以执行Get-S3Bucket并查看我帐户中的所有存储桶,因此我知道它已正确配置.
如果我做:
> $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
Run Code Online (Sandbox Code Playgroud)
如果我$f[0].fullName单独做,我会得到对象的完整路径.但是,它有空格.这可能是个问题吗?
当您像从命令行填写缺少的参数时,需要指定它们的文字字符串值。当我在本地模仿你的问题时:
PS C:\> Write-S3Object
cmdlet Write-S3Object at command pipeline position 1
Supply values for the following parameters:
BucketName: MyTestBucketNameHere
Key: $testName
File: C:/test.txt
Run Code Online (Sandbox Code Playgroud)
我最终在 S3 上得到了一个文件,其密钥名为$testName,因为在该上下文中不会评估变量。同样,您会收到“FilePath 属性指示的文件不存在!” 错误,因为您的文件系统中没有名为$f[0].fullName.
将单个文件写入 S3 的示例:
PS C:> Write-S3Object -BucketName "MyTestBucketName" -Key "file.txt" -File "C:/test.txt"
Run Code Online (Sandbox Code Playgroud)
要将所有文件写入 S3:
PS C:\> (Get-ChildItem -filter "*.flv") | % { Write-S3Object -BucketName "MyTestBucketName" -File $_ -Key $_.name}
Run Code Online (Sandbox Code Playgroud)
这将首先获取当前目录中文件类型为 flv 的所有文件,对于每个对象(由百分号表示),我们将把文件(由 表示$_)写入 MyTestBucketName,其 Key 是当前目录的 name 属性。正在迭代的文件。
| 归档时间: |
|
| 查看次数: |
8416 次 |
| 最近记录: |