Delete files using REST API

Hello there.
I’m trying to delete my uploaded files using REST API.
When I send the request to the file address with the DELETE method, it returns an error with code 153 and message of Could not delete the file..
I looked up the document for code 153 in Errors, but I didn’t find it.
Does anyone know what is the problem here?

Note: I’m sending the MasterKey and AppID in headers.
Update: Does it relate to delete the object before the file deletes? Because I’m trying to delete the file first.

This is the code I use to delete files.

  await Parse.Cloud.httpRequest({
          url: `http://serverIPadress:1337/parse/files/${filename}`,
          method: 'DELETE',
          headers: {
              'X-Parse-Master-Key' : 'YourMasterKey',
              'X-Parse-Application-Id': 'YourAppId'

Try it. It works for me with S3 Storage adapter. Also was working with Minio Storage adapter.



I don’t think so. Files and ParseObjects has no connection

The error means that deleting the file failed for some reason. Depending on the storage adapter you are using (whether you store the file in MongoDB, in AWS S3, etc.) this can have various reasons. The Parse Server logs should contain an entry Error deleting a file: ... that should give you more details. One reason could be that the file does not exist, ie. has already been deleted, or parse server doesn’t have the access rights to delete a file in the storage.

Good find, this error code seems to be missing in the docs. Would you want to open an issue in the docs repo? If you want to go even further, we would gladly review your PR for adding the error code.

Parse Object and Parse File are separate elements, deleting one does not delete the other (yet), unless you write some custom Cloud Code where one triggers the other.

1 Like

Thanks, @Manuel for your response.
I’m using default configurations for storing files, I mean MongoDB.
And the file exists. I check it myself with a MongoDB client.
The error should be something else. Maybe it’s about access.
The problem is, I’m using MongoDB clusters. How can I check the access?

Also created an issue with Missin Content label for that 153 code (:

Thanks for opening the docs issue, it would be great if you could reference this tread with the issue for traceability.

Did you have a look at the Parse Server logs as I suggested previously? It may give you a direct hint on why the deletion fails.

That shouldn’t be a problem. The access rights are defined by the database user that Parse Server is using to connect to the database. You would look into MongoDB user management.

Yes, there are some logs. But I don’t know it’s related to pictures or not. They are for Product and Blog classes.

@Manuel I asked our DevOps about Mongo. It uses admin for access rights.
How about checking the source code and see when the code 153 returns? (:

These entries are about deletes objects in the Blog class. In my comment earlier I quoted the entry you would be looking for. Verbose logging should be enabled.

That would of course be the most investigative approach. You could set a breakpoint in the Parse Server file adapter and just look the the error message, but this error message should be in the logs as well, as I mentioned above.

No, there was no such error. What is verbose logging and how should I enable it?

The Parse Server GitHub page explains more about logging.

I assume the error is thrown in the FilesRouter:

The logger should actually log the error regardless of verbose logging, because it is an error. If you debug Parse Server while running and trying to delete a file, set a breakpoint at line 229 and look at variable e, which is the original error that should give you more details.

Thanks, @Manuel for your time.
I tested the @uzaysan’s way and it’s working fine!
It’s kind of weird because I used fetch for requesting and that was not working. Now that I’m using Parse.Cloud.httpRequest it’s working as expected (:

Can you tell what the difference was between your previous code and the code that works now? Just to find out whether there may be an issue in Parse Server we should address.

Sure. This is my prev code:

fetch(editedURL, {
    method: 'DELETE',
    headers: {
        'X-Parse-Application-Id': appId,
        'X-Parse-Master-Key': masterKey,
    .then((res) => resolve(res.json()))
    .catch(() => reject('Error in deleting the file(s).'));

For reference issue 757 in the docs repo.

1 Like