Improve attachment file handling: use one new function to create a temp