Using Martin’s code above, this is how I was able to do it:
$data = [
"files" => $file,
"ref" => "blocks.media", // the name of the dynamic zone and component
"field" => "image", // the field within the component
"refId" => 5, // the id of the component "media" block
];
I hope this helps!