Parse-сервер: удаление объекта, связанного с файлом, хранящимся на S3, не удаляет файл - PullRequest
0 голосов
/ 25 октября 2018

Я работаю с экземпляром ParseServer, который успешно настроен для использования S3Adapter для хранения моих загруженных файлов через ParseServer.

Я могу загрузить файл в столбец File с именем image в моемтаблица базы данных называется item.Я вижу, что файл был сохранен на S3 с URL-адресом: https://s3-ap-southeast-2.amazonaws.com/{BUCKET_NAME}/{FILE_NAME}.jpg

Этот файл также общедоступен.

У меня также есть следующая облачная функция, которая предназначена для удаленияфактический загруженный файл с S3 до удаления элемента, связанного с файлом.

Parse.Cloud.beforeDelete("item", async (request) => {       
  // Checks if "image" has a value
  if (request.object.has("image")) {

    var file = request.object.get("image");
    var fileName = file.name();
    console.log(file.name());   // The name is correct
    console.log(file.url());    // The URL is correct as above

    const response = await Parse.Cloud.httpRequest({
      method: 'DELETE',
      url: file.url(),
      headers: {
        "X-Parse-Application-Id": "APPLICATION_ID",
        "X-Parse-Master-Key" : "a-super-secret-master-key"
      },
      success: function(httpResponse) {
        console.log('*** Deleted the file associated with the item job successfully.');
        //return httpResponse;
      },
      error: function(httpResponse) {
        console.error('*** Delete failed with response code ' + httpResponse.status + ':' + httpResponse.text);
        //return httpResponse;
      }
    });

    console.log("---" + response)
  } else {
    console.log('*** item object to be deleted does not have an associated image (File). No image to be deleted.');
    //return 0;
  }
});

При попытке удалить элемент выдается сообщение об ошибке, как показано ниже:

<?xml version="1.0" encoding="UTF-8"?><Error><Code>AccessDenied</Code><Message>Access Denied</Message><RequestId>63FC6B3711D87F65</RequestId><HostId>/A3Uoq26QT0dHWnWBttPZJg53fn6+zIVI4rncxeNurIu9fVIbxOJn0GxgvrGVpt+pfZXkopYdQY=</HostId></Error>

MyВопрос в том, что пошло не так с моим кодом, и рекомендуется ли использовать Parse.Cloud.httpRequest для удаления файла из S3 или использовать AWS REST API для удаления файла?

...