2014-03-04 56 views
0
  1. 我有我的RESTapi服務器存儲AWS公共密鑰/密鑰。我還存儲客戶端公鑰/密鑰(客戶端是我創建的用戶 - 它有權進行CORS請求)。如何簽署從外部服務器執行的S3請求

  2. 我有我的,這將文件上載直接S3存儲外部服務器。但我不想在其上存儲AWS憑據 - 我希望它在上傳之前以某種方式調用主服務器來簽名請求,然後直接將文件上傳到s3。

現在我使用aws-sdk外部服務器上是這樣的:

var aws = require('aws-sdk'); 

aws.config.update({ 
    "accessKeyId": process.env.AMAZONS3_ACCESSKEY_ID, 
    "secretAccessKey": process.env.AMAZONS3_ACCESSKEY, 
    "region": process.env.AMAZONS3_REGION_CLOUD, 
}); 

var s3 = new aws.S3({ params: { Bucket: 'myCustomBucket' } }); 

s3.putObject(...); 

現在我需要改變,因此外部服務器將調用主服務器與一些S3 PARAMS和它會被背面簽名密鑰或類似的東西,它會用它來上傳文件...

所以主服務器上的端點應該怎麼樣子(什麼PARAMS中應該消耗以及如何生成號)? 然後我可以如何使用標誌從外部服務器發出請求?

回答

0

這裏http://docs.aws.amazon.com/aws-sdk-php/guide/latest/service-s3.html下部分看一看創建presigned網址

// Get a command object from the client and pass in any options 
// available in the GetObject command (e.g. ResponseContentDisposition) 
$command = $client->getCommand('GetObject', array(
    'Bucket' => $bucket, 
    'Key' => 'data.txt', 
    'ResponseContentDisposition' => 'attachment; filename="data.txt"' 
)); 

// Create a signed URL from the command object that will last for 
// 10 minutes from the current time 
$signedUrl = $command->createPresignedUrl('+10 minutes'); 

echo file_get_contents($signedUrl); 
// > Hello! 

創建命令(在你的情況下,認沽不是GET)一臺服務器上,通過這個來,這將創建presigned主服務器網址。將其傳回外部服務器執行。

相關問題