A search for the decays of the Higgs and Z bosons to J/psi gamma and Upsilon(nS)gamma (n = 1,2,3) is performed with pp collision data samples corresponding to integrated luminosities of up to 20.3 fb(-1) collected at root s = 8 TeV with the ATLAS detector at the CERN Large Hadron Collider. No significant excess of events is observed above expected backgrounds and 95% C.L. upper limits are placed on the branching fractions. In the J/psi gamma final state the limits are 1.5 x 10(-3) and 2.6 x 10(-6) for the Higgs and Z boson decays, respectively, while in the Upsilon(1S, 2S, 3S)gamma. final states the limits are (1.3, 1.9, 1.3) x 10(-3) and (3.4, 6.5, 5.4) x 10(-6), respectively.