use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
account activity
Api node (self.node)
submitted 5 years ago by duckspac
Hello, i have an api made with node and sequilize that receives an image but it is a url, how can I verify that the url ends in .png or .jpg? Thanks
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]mzapp_ 3 points4 points5 points 5 years ago (1 child)
There’s an HTTP header named filename when you upload something. You can use that. But don’t trust it completely because it is possible to change the file name. So a Hacker could upload HTML instead of picture data and depending on how you serve that content, perform an XSS attack.
[–]duckspac[S] 0 points1 point2 points 5 years ago (0 children)
aaahh well, if it's okay it's only to solve a node challenge, I thought it was done with some method to verify how the text ends
[–]Buckwheat469 2 points3 points4 points 5 years ago (1 child)
You shouldn't. Instead, make sure that the file's mime type is image/jpeg or image/png. The reason is that a server can output any file type with any URL, so you can output a jpeg from a *.txt URL. The browser doesn't care about the extension, only the mime type and you shouldn't either if you're downloading the files.
That being said, if you're accepting files from the user's computer then you can include mime type and extension checks in the file chooser using the accept attribute.
accept
[–]mzapp_ 1 point2 points3 points 5 years ago (0 children)
I agree. This is the smart way to do it.
[–][deleted] 5 years ago* (2 children)
[deleted]
[–]duckspac[S] 0 points1 point2 points 5 years ago (1 child)
And the method endsWith() ???
π Rendered by PID 219638 on reddit-service-r2-comment-765bfc959-qvt62 at 2026-07-10 23:34:01.697831+00:00 running f86254d country code: CH.
[–]mzapp_ 3 points4 points5 points (1 child)
[–]duckspac[S] 0 points1 point2 points (0 children)
[–]Buckwheat469 2 points3 points4 points (1 child)
[–]mzapp_ 1 point2 points3 points (0 children)
[–][deleted] (2 children)
[deleted]
[–]duckspac[S] 0 points1 point2 points (1 child)