Cannot remove audio data on AWS-S3 in a Parse-Server app

给你一囗甜甜゛ 提交于 2019-12-13 01:24:28

问题


I am having some hard time to make things work properly while using AWS-S3 with Parse-Server on Heroku.

On AWS, I have an S3 bucket called mybucket and a user called mybucket-aws with this policy associated:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "s3:*"
            ],
            "Resource": [
                "arn:aws:s3:::mybucket",
                "arn:aws:s3:::mybucket/*"
            ]
        }
    ]
}

Beside, on Heroku I have a parse-server set like this:

var express = require('express');
var ParseServer = require('parse-server').ParseServer;
var path = require('path');
var mongo = require('mongodb');
var MongoClient = mongo.MongoClient;

var databaseUri = process.env.DATABASE_URI || process.env.MONGODB_URI;

if (!databaseUri) {
  console.log('DATABASE_URI not specified, falling back to localhost.');
}

var api = new ParseServer({
  databaseURI: databaseUri,
  cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
  appId: process.env.APP_ID,
  masterKey: process.env.MASTER_KEY,
  filesAdapter: "@parse/s3-files-adapter",
  serverURL: process.env.SERVER_URL,
  publicServerURL: process.env.PARSE_PUBLIC_SERVER_URL,
  appName: 'MyApp',
  .........
});

And here is the swift code I use in my iOS app when uploading audio data to the server:

//audioFileName is the name of the sound file.
do {let soundData = try Data(contentsOf: getDocumentsDirectory().appendingPathComponent(audioFileName)),
    parse_Sound = PFFile(name: "Voice", data: soundData)
    parse_Sound?.saveInBackground(block: {
        (succeeded:Bool, error:Error?) in
        if succeeded {
            // Keep working all is OK.
        } else {print("Error: \(error ?? "" as! Error)")}
    })
} catch let error {
    print("Error:\n" + error.localizedDescription)
}

Finally, here is the javascript code run through a cloud function, that is used when I want to remove the audio data from the server. It is called through the iOS app. And it does not (fully) work.

const aws = require('aws-sdk');
.........

(function() {
 var destroyPromises = [];
 const s3 = new aws.S3();
 for (i = 0; i < myArray.length; i++) {
   // Let us remove the sound data:
   destroyPromises.push(s3.deleteObject({
     Bucket: "mybucket",
     Key: myArray[i].get("audio")
   }).promise());
   destroyPromises.push(myArray[i].destroy({}));
 }

Since the rest of the data is removed as expected, I think it is not a mistake in the usage of promises. Only the audio data on AWS/S3 is not removed as it should. Knowing I can write data to the bucket (when uploading), I suppose I have write-access and therefore should also be able to delete data. But I am not 100% sure about that and suspect something may be wrong in my permissions setting. Anyway, can someone see why I cannot delete the audio data in my s3-bucket and tell me what I should do?

来源:https://stackoverflow.com/questions/50013876/cannot-remove-audio-data-on-aws-s3-in-a-parse-server-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!