Trouble uploading post attachment

Hello.
I’m developing a plugin, that at some point attaches a remote file (DigitalOcean Spaces) to a post, programmatically. The plugin works well on normal WP installations, but fails when using Bedrock.

The relevant part of the code looks like this:


$upload = wp_upload_bits($value, null, file_get_contents($value));
										$filename = $upload['file'];
										$error_upload = $upload['error'];
										if ($error_upload) $logger->log('<blockquote>An error ocurred when uploading the file: '. $error_upload . '</blockquote>');
										$wp_filetype = wp_check_filetype($filename, null );
										$attachment = array( //Attachments are special posts
											'post_mime_type' => $wp_filetype['type'],
											//'post_name' => 'attachment-n', //This is set automatically
											'post_title' => 'Fetched '. $key . ' for post ' . $post_id,
											'post_content' => $doc_field['desc'],
											'post_excerpt' => str_replace('_',' ', $key) .' for post titled: ' . $fpost[$title_key], //Caption
											'post_status' => 'inherit'
										);
										$attach_id = wp_insert_attachment( $attachment, $filename, $post_id );
										if(!is_wp_error($attach_id) && intval($attach_id) > 0) { //Success attaching
											$logger->log('<blockquote>Success attaching the file to the post with Id "' . $post_id . '"</blockquote>');
										} else { //Some error occurred
											$logger->log('<blockquote>Some error occurred when attaching the file to the post with Id "' . $post_id . '"</blockquote>');
										}

The script stalls at the beginning, when wp_upload_bits function is used. No visible error or indication on the debug log.

Your suggestions will be greatly appreciated.

Thanks