Check if file ID exists before inserting into DB

File IDs collisions are improbable but possible. This check avoids this from happening.