Site icon Hip-Hop Website Design and Development

wordpress REST-API upload image to ACF

I created my own API using WordPress Rest-API. I successfully saved all data in wordpress backend but I don’t know how to get and save the data if file/image.

    register_rest_route( 'mlcs/v1', '/save_data', array(
        'methods' => 'POST',
        'callback' => array( $this, 'save_data_post' ),
        'args' => array(
            'name' => array(
                'required' => true,
                'type' => 'string',
            ),
            'image' => array(
                'required' => true,
                'type' => 'string',
            ),
        )
    ) );

public function save_data_post( $request ) {
   $name = $request->get_param('name');
   $image = $request->get_param('image');

   //save the data in ACF
   update_field('name_field', $name ); //text type

   //not saving
   update_field('image_field', $image ); //image type

}