parse-server: Having problems deleting file via REST api - getting 404

I have some cloud code that I’m calling from my parse instance that is the following:

Parse.Cloud.httpRequest({
            method: 'DELETE',
            url: url,
            headers: {
                'X-Parse-Application-Id': process.env.APP_ID,
                'X-Parse-Master-Key': process.env.MASTER_KEY
            }
        }).then(function(httpResponse) {
            console.log(httpResponse.text);
        }, function(httpResponse) {
            console.error('Request failed with response code ' + httpResponse.status);
        })

I’m getting the message Request failed with response code 404 in the heroku log. I’m positive that the url exists that I’m passing in because I can hit it in my browser and it downloads the image that I am trying to delete.

I’m also positive that my process.env.APP_ID and process.env.MASTER_KEY are correct as well since I’ve printed those to the log as well and seen them.

Is there another step that I’m missing here?

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 17 (6 by maintainers)

Most upvoted comments

At long last, I determined why the endpoint was not working, and always returning a 404. The name of the request URL is very important! It’s NOT the full file url as one would expect. For example, the full url of the files on my parse-server look like:

http://myserver.com/parse/files/MqX4RIjBpnVgUg9lRrxmWRsDVmqR5SCOaYmnSpnx/fa4492b3be10b5eac60881d2c6462730.png

To get the /files endpoint to DELETE this file the request URL is:

http://site2img-api.herokuapp.com/parse/files/fa4492b3be10b5eac60881d2c6462730.png

So, when the docs mentioned “To delete a file, send a DELETE request to the files URL, postfixed with the name of the file”, it’s correct! You just need to get rid of that extra /xxxxxxxxx before the actual filename.

Here’s my working cloud code…

Parse.Cloud.httpRequest({
	method: "DELETE",
	url: "http://.../parse/files/664a8e00a0ccd0fd44ca1d4e4a0c2ca5.png",
	headers: {
		'X-Parse-Application-Id':'MqX4RIjBpnVgUg9lRrxmWRsDVmqR5SCOaYmnSpnx',
		'X-Parse-Master-Key':'ZjpLGVWBJujDdElxxGeEh2fpS041PiQSAqk8cwCi',
	}
}).then(function(httpResponse) {
   //... it worked!!
}, function(httpResponse) {
	console.error('Delete request failed with response code ' + JSON.stringify(httpResponse));
});

@astanton how did you fix this problem?

Well I was following this here:

https://parse.com/docs/rest/guide/#files-deleting-files

And this here to make the rest call from the cloud code:

https://parse.com/questions/making-a-rest-call-from-within-cloud-code

According to that, it says I can use Parse.Cloud.httpRequest to make REST calls, so I am not sure what you are referring to as that not the correct ways. Both of those have links to the docs and that is what I followed.