Best way to limit file size when downloading a url
So im adding a way to ahve custom images for xp but dont want to have people put in custom urls that have it download a file thats over 10gb lol. Best way to avoid this? And no im not limiting to discord file uploads unless absolutely necessary
6 Replies
I'm not sure what you mean, are you downloading those images on your end?
Or are users UPLOADING them to your server?
correct
is there some frontend sending this to a backend? Would like more context of the system
Generally you would just grab the first few bytes of the data, check if it matches the magic bytes of for example a PNG https://en.m.wikipedia.org/wiki/List_of_file_signatures
List of file signatures
This is a list of file signatures, data used to identify or verify the content of a file. Such signatures are also known as magic numbers or Magic Bytes.
Many file formats are not intended to be read as text. If such a file is accidentally viewed as a text file, its contents will be unintelligible. However, sometimes the file signature can be re...
And then check the length of the data and if it is above a certain limit, give an error saying like file size is too large.
If the magic bytes of a PNG does not match then you know it is not a valid PNG
nope just a discord bot
got it thx
on another note what the fuck am i doing wrong here???
why is it telling me theres no method to override???
someone please help me hbefore i have a breakdown here