我有刪除一次對多個對象的問題..刪除多個對象的Amazon S3 PHP SDK
使用這個庫 - https://github.com/aws/aws-sdk-php-laravel - 我沒有問題,與任何其他使用該庫(推杆,獲得,刪除單一對象等)
try {
$s3 = AWS::get('s3');
$s3->deleteObjects(array(
'Bucket' => $bucket,
'Objects' => $json['attachmentArray']
));
return "Success deleting files.";
} catch (S3Exception $e) {
return "There was an error.\n";
}
deleteObjects亞馬遜Docs- http://docs.aws.amazon.com/AmazonS3/latest/dev/DeletingMultipleObjectsUsingPHPSDK.html
我得到恢復"Success deleting files.";
,但文件沒有被DELE特德。
我斗的名字是正確的,$json['attachmentArray']
根據文檔是正確的格式(再次,我有喜歡放其他方面沒有任何問題,獲取,刪除)
誰能指出哪裏我嗯搞砸了? 謝謝。
編輯:
試圖讓更多的信息:從一個角度功能,Laravel端點
我張貼信息。
這裏是角功能(火力地堡URL隱藏):
$scope.deleteFile = function() {
var r=confirm("Are you sure you want to delete this task & of it's all attachments?");
if (r==true)
{
var attachmentArray = [];
var atttachData = new Firebase('https://*.firebaseio.com/attachments');
atttachData.on('value', function(dataSnapshot) {
dataSnapshot.forEach(function(childSnapshot) {
var key = childSnapshot.val().key;
// attachmentArray.push(key); I tried this
attachmentArray.push({Key:key});
});
});
method: "POST",
url: '/delete_task',
data: {attachmentArray:attachmentArray},
headers: {'Content-Type': 'application/json'},
}).success(function(data){
console.log(data);
});
}
}
這裏是我試圖讓deleteObjects(從@Kevin佛羅里達更新的代碼我Laravel控制器:
public function delete_task() {
$request = Request::instance();
$task = $request->getContent();
$json = json_decode($task, TRUE);
$bucket ='bucketname/team1';
// return $json['attachmentArray'];
$s3 = AWS::get('s3');
if(!$s3->deleteObjects(array(
'Bucket' => $bucket,
'Objects' => $json['attachmentArray']
))) {
return "error";
} else {
return "success";
}
}
現在這返回一個500服務器錯誤..我想我格式化$json['attachmentArray'];
不正確?不確定;/
編輯2:
角功能
$scope.deleteFile = function() {
var r=confirm("Are you sure you want to delete this task & of it's all attachments?");
if (r==true)
{
var attachmentArray = [];
var atttachData = new Firebase('https://***/attachments');
atttachData.on('value', function(dataSnapshot) {
dataSnapshot.forEach(function(childSnapshot) {
var url = childSnapshot.val().url;
var name = childSnapshot.val().name;
var id = childSnapshot.val().id;
var key = childSnapshot.val().key;
attachmentArray.push(key);
});
});
$http({
method: "POST",
url: '/delete_task',
data: {team:$scope.team,attachmentArray:attachmentArray,lastSegment:lastSegment},
headers: {'Content-Type': 'application/json'},
}).success(function(data){
console.log(data);
});
}
}
Laravel控制器
public function delete_task() {
$s3 = AWS::get('s3');
$task = Input::all();
$bucket ='teamite/team'.$task['team'];
//make the array for Objects on this side
foreach ($task['attachmentArray'] as $value) {
$array[] = array('Key' => $value);
}
// return $task['attachmentArray'][0];
$result = $s3->deleteObjects(array(
'Bucket' => 'teamite/team1',
'Objects' => $array
));
return $result;
}
我登錄亞馬遜在控制檯這樣的響應:
=====================
Debug output of model
=====================
Model data
-----------
This data can be retrieved from the model object using the get() method of the model (e.g. $model->get($key)) or accessing the model like an associative array (e.g. $model['key']).
[Deleted] => Array
(
[0] => Array
(
[Key] => 4700pzgds4i_ad.jpg
)
[1] => Array
(
[Key] => xxvu29ms4i_ad.jpg
)
)
[RequestId] => 477F0DA04101D82E
所以現在看來一切正常。但是這些對象並沒有被刪除? 我還做了什麼錯?在這個瘋狂!
沒有足夠的信息對我的幫助,但我建議你看一下服務器上文件的所有權的權限。 –
我可以爲您提供什麼更多信息?這是一個公共桶。我從這個存儲桶中刪除單個對象沒有問題。 –
$ json ['attachmentArray']的值是什麼? –