我试图通过下面的代码从s3对象中读取内容。
$content = $s3Client->getObject(
array(
'Bucket'=> $bucketName,
'Key' => $pathToObject,
'ResponseContentType' => 'text/plain',
)
);
我得到了以下答复
GuzzleHttp \ Psr7 \ Stream对象( [stream:GuzzleHttp \ Psr7 \ Stream:private] =>资源ID#87 [size:GuzzleHttp \ Psr7 \ Stream:private] => [seekable:GuzzleHttp \ Psr7 \ Stream:private] => 1 [可读:GuzzleHttp \ Psr7 \ Stream:private] => 1 [writable:GuzzleHttp \ Psr7 \ Stream:private] => 1 [uri:GuzzleHttp \ Psr7 \ Stream:private] => php:// temp [customMetadata:GuzzleHttp \ Psr7 \ Stream:private] =>数组 ( )
)
在S3中阅读对象内容将提供任何帮助。
答案 0 :(得分:2)
实际上是它的返回Psr7 \ Stream对象。
因此,如果需要从PSR Stream获取内容,则必须从对象调用getContents()方法。
public class soundCont : MonoBehaviour {
private static float musicVolume = 1f;
private static float SetVolumeFX = 1f;
private void Start()
{
musicVolume = Musicafondo.instance.musicSource.volume;
}
void Update ()
{
MusicBack.instance.musicSource.volume = musicVolume;
MusicBack.instance.efxSource.volume = SetVolumeFX;
MusicBack.instance.efxSourceEnemy.volume = SetVolumeFX;
DontDestroyOnLoad(this.gameObject);
}
public void SetVolume(float vol)
{
musicVolume = vol;
}
public void SetVolumeFx(float vol2)
{
SetVolumeFX = vol2;
}
}
希望这会对实际使用SDK版本3的人有所帮助。
此处https://docs.aws.amazon.com/aws-sdk-php/v3/api/class-GuzzleHttp.Psr7.Stream.html的规范
答案 1 :(得分:0)
AWS S3的getObject返回可以以两种方式呈现的流对象。
require 'vendor/autoload.php';
use Aws\S3\S3Client;
use Aws\S3\Exception\S3Exception;
$bucket = '*** Your Bucket Name ***';
$keyname = '*** Your Object Key ***';
$s3 = new S3Client([
'version' => 'latest',
'region' => 'us-east-1'
]);
try {
// Get the object.
$result = $s3->getObject([
'Bucket' => $bucket,
'Key' => $keyname
]);
// Display the object in the browser.
header("Content-Type: {$result['ContentType']}");
echo $result['Body'];
} catch (S3Exception $e) {
echo $e->getMessage() . PHP_EOL;
}
//就我而言,我需要创建已启用的预签名请求 加密
$command = $s3Client->getCommand('GetObject', [ 'Bucket' => $bucket_name, 'Key' => $file_name ]); $result = $s3Client->createPresignedRequest($command, '+10 minutes'); $presignedUrl = $result->getUri()->__toString();
//无需预先签署请求即可获取uri的解决方案
$result = $s3Client->getObject([
'Bucket' => $bucket_name,
'Key' => $file_name
]);
$fileUrl = $result->getUri()->__toString();