Button placement in the container/widget

In our case, each container/widget has one primary CTA. Because each widget/container contain important data points related to that widget. User may choose to download the data of the widget.

Problem: We have a layout switcher wherein the user can toggle between table and card, user can apply filters. In most of our widget, the download button is the primary CTA for the user.

What should be the ideal placement for CTA in the container/widget? Should it be placed at the end of the widget? or the widget heading level.

For your reference, a wireframe is added below.

enter image description here