0

I'm currently building a project based on the Parse.com backend that includes uploading files. Users can upload files and then access a list of these/download them, this all works fine. However, I'm not sure how to implement the command to delete an upload. From the Parse.com forums as well as the Parse support document, the call is:

curl -X DELETE \
    -H "X-Parse-Application-Id: <YOUR_APPLICATION_ID>" \
    -H "X-Parse-Master-Key: <YOUR_MASTER_KEY>" \
    https://api.parse.com/1/files/<FILE_NAME>

I've had a bit of a look online but the only curl commands I can find to execute commands is curl_setopt. I imagine the above needs to be converted, can anybody help with this or point me in the right direction?

So basically I need to be able to press a button on a website (through PHP) and have it run the above command.

Thanks in advance

1
  • 1
    You can use PHP's cURL library to do this. If you are interested, I have actually implemented a lightweight REST client class based on cURL. You are free to use it. Here is the link: github.com/mikecbrant/php-rest-client Commented Apr 17, 2014 at 20:30

1 Answer 1

1

According to given info you have to set custom request method 'DELETE' (by CURLOPT_CUSTOMREQUEST option) as well as custom headers (by CURLOPT_HTTPHEADER option).

So the code should look like this:

$options = array(
    CURLOPT_NOBODY => 0,
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_SSL_VERIFYPEER => false,
    CURLOPT_CUSTOMREQUEST => 'DELETE',
    CURLOPT_HTTPHEADER => array(
        'X-Parse-Application-Id: <YOUR_APPLICATION_ID>',
        'X-Parse-Master-Key: <YOUR_MASTER_KEY',
    ),
    CURLOPT_URL => 'https://api.parse.com/1/files/<FILE_NAME>',
);
$ch = curl_init();
curl_setopt_array($ch, $options);
$response = curl_exec($ch);
echo $response;
Sign up to request clarification or add additional context in comments.

4 Comments

Hi, Thank you very much for the response. I'll try it out in a bit. For now I was looking at AJAX, and have the following code, but when I run it nothing happens. Is this do you think an acceptable way of doing of or will I need to do it in PHP? pastie.org/private/tcse5mfx4yodcptelznbw
then probably your account is not okay... try it out with a rest client addon first
@theuseduser I'm not familiar with parse.com API. I just gave answer to your question in CURL terms.
after much playing around, I've finally managed to get it to work, thank you very much hindmost!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.