We study the rheology of cornstarch suspensions, a non-Brownian particle system that exhibits discontinuous shear thickening. Using magnetic resonance imaging (MRI), the local properties of the flow are obtained by the determination of local velocity profiles and concentrations in a Couette cell. For low rotational rates, we observe shear localization characteristic of yield stress fluids. When the overall shear rate is increased, the width of the sheared region increases. The discontinuous shear thickening is found to set in at the end of this shear localization regime when all of the fluid is sheared: the existence of a nonflowing region, thus, seems to prevent or delay shear thickening. Macroscopic observations using different measurement geometries show that the smaller the gap of the shear cell, the lower the shear rate at which shear thickening sets in. We, thus, propose that the discontinuous shear thickening of cornstarch suspensions is a consequence of dilatancy: the system under flow attempts to dilate but instead undergoes a jamming transition, because it is confined. This proposition is confirmed by an independent measurement of the dilation of the suspension as a function of the shear rate. It is also explains the MRI observations: when flow is localized, the nonflowing region plays the role of a dilatancy reservoir which allows the material to be sheared without jamming.