You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Having problems deleting file via REST api - getting 404 #1765
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.
Could you post some parse server logs as well? Also, was this file originally created on api.parse.com? If so, you'll need to use api.parse.com to delete it.
@drew-gross would that be in the Heroku Config Variables that I set that? Or in my index.js file where I'm calling new ParseServer() and pass that to it in the config object?
@drew-gross Sorry for the noobness, but where will these logs appear after I add that flag? I assumed they would add more stuff to the application server log that I see on Heroku but nothing more is showing up there.
That flag will cause every request and response to be logged. If there is nothing showing up, then there must be some other issue with your configuration.
That is not the correct way to delete files. Please check the docs or ask a question on Stack Overflow if you are having trouble, this repo is for reporting bugs in Parse Server.
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.
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:
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.
Activity
astanton commentedon May 13, 2016
Just for reference, this is what I was trying to follow to delete the files.
https://parse.com/questions/how-can-i-delete-a-file
drew-gross commentedon May 13, 2016
Could you post some parse server logs as well? Also, was this file originally created on api.parse.com? If so, you'll need to use api.parse.com to delete it.
astanton commentedon May 13, 2016
@drew-gross No these were created with the server hosted on Heroku.
Here is the log of a delete request that fails:
2016-05-13T20:14:43.495784+00:00 heroku[router]: at=info method=DELETE path="/parse/files/SBcAs3A0hkTsaoU5JW7GP4YlRVNfMNo7tRg1rQJy/774d87665ad847441f9b31bd7b0ea9a3_file.bin" host=app-name.herokuapp.com request_id=3f12a88e-6857-4cc0-9c6e-b889bdfd7f0b fwd="54.166.161.252" dyno=web.1 connect=0ms service=4ms status=404 bytes=626And in this case, the
urlthat was passed into theParse.Cloud.httpRequestcall as shown in my original post was:http://app-name.herokuapp.com/parse/files/SBcAs3A0hkTsaoU5JW7GP4YlRVNfMNo7tRg1rQJy/774d87665ad847441f9b31bd7b0ea9a3_file.binAnd if I hit that URL directly, it downloads the picture to my laptop.
drew-gross commentedon May 13, 2016
Thats a Heroku log. I need the Parse Server log. Set
verbose: truein your server options to enable logging.astanton commentedon May 13, 2016
@drew-gross would that be in the Heroku Config Variables that I set that? Or in my index.js file where I'm calling new ParseServer() and pass that to it in the config object?
drew-gross commentedon May 13, 2016
In your
index.jswhere you callnew ParseServer().astanton commentedon May 13, 2016
@drew-gross Sorry for the noobness, but where will these logs appear after I add that flag? I assumed they would add more stuff to the application server log that I see on Heroku but nothing more is showing up there.
drew-gross commentedon May 13, 2016
That flag will cause every request and response to be logged. If there is nothing showing up, then there must be some other issue with your configuration.
astanton commentedon May 14, 2016
@drew-gross any idea how I can figure out what else may be wrong with the configuration? Here's the call that creates the new server object.
astanton commentedon May 19, 2016
@drew-gross okay so I figured out the issue with verbose and I now have it working.
When I call the code in question, I don't even see the DELETE request in the parse-server logs at all.
I have this running locally and here is the exact code I'm running:
When I put a break point down in the error function, "a" is just an array and they all say error 404.
Also, this is the exact output after I make that call, on the log:
So it's odd that the DELETE call is not even showing up in there. Am I calling it wrong with the Parse.Cloud.httpRequest method or something?
And again, if I hit the values for fileUrl in my browser, it downloads the images I'm trying to delete so the path is correct.
This is on the latest released version of parse-server, 2.2.10.
drew-gross commentedon May 19, 2016
That is not the correct way to delete files. Please check the docs or ask a question on Stack Overflow if you are having trouble, this repo is for reporting bugs in Parse Server.
astanton commentedon May 19, 2016
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.
ZhenanH commentedon May 21, 2017
@astanton have you solved the problem, I have similar problem. I used Parse.Cloud.httpRequest to make REST calls to delete photos, but always fails.
junal commentedon Oct 5, 2017
@astanton how did you fix this problem?
iatek commentedon Mar 8, 2018
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.pngTo get the /files endpoint to DELETE this file the request URL is:
http://site2img-api.herokuapp.com/parse/files/fa4492b3be10b5eac60881d2c6462730.pngSo, 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....
JacobJT commentedon Mar 9, 2018
I think it may also have had to do with you using ngrok in the request instead of your actual server URL.
emadehsan commentedon Apr 26, 2018
@iatek you are right! remove the Application Id from file URL
If file is at: https://YOUR.PARSE-SERVER.HERE/parse/files/SOME_APP_ID/profile.png, you need to make request at https://YOUR.PARSE-SERVER.HERE/parse/files/profile.png
Docs don't explicitly specify this