encode resource automatically