Clean handling of files in API