A possible solutions depends on what file types you want to allow to be uploaded.
For simplicity I will assume that only jpegs.
You will need to scan the loaded bytes and look for valid Jpeg headers. the bytes that are supposed to he in headers are not compliant to the jpeg specs reject the file.
Just to sleep better at night, do the same server side if you need to upload the jpeg on server.
If you also wand to upload other file formats .png... you need to scan for their specific headers.
But what should i check for jpg files and what for png files??.. Where can i check info about??.. I found this code around to check if a byteArray is a valid jpg file..
//get the last two bytes
var secondToLastByte:uint = bytes.readUnsignedByte();
var lastByte:uint = bytes.readUnsignedByte();
//if the last two bytes don’t match the EOI segment header at the end of the file
//then we know it is invalid
if((secondToLastByte == 255 && lastByte == 217) || (secondToLastByte == 217 && lastByte == 0))
// valid jpg file
Is this code good.. ??... How can i know what to check for jpg, png or other files??
Thx a lot
Probably fisr thing would be to check for size to be at least the size required for the header.
I don't know the jpeg specification by heart. You need to go to the specification document.
something like this or other:
The you will see the header structure.
Read the header bytes make sure there are enough nytes for the header if not discard.
Check for all the information in the headers to be there if they are good if they not discard.
I never done it so I don't know if the code you found is enough or not. Just told you what I would do.
Also never said thi way is straight forward, you need to do you reasearch and implement it.
Also look into the JPEGEncoder class in the flex framework the encode the header there.
You can draw inspiration from that logic.
If there is other faster or easier way, I would be happy to be corrected.
Because of your advices i can now begin to research.
Thx a lot