NAME

Twilio::Http::File - A file to upload in a form

SYNOPSIS

use Twilio::Http::File;

my $inquiry = $client->trusthub->v1->compliance_registration_inquiries->create(
  $end_user_type, $phone_number_type,
  {
    file      => Twilio::Http::File->new('/path/to/license.pdf', undef, 'application/pdf'),
    file_name => 'license.pdf',
  }
);

DESCRIPTION

A form value that is a Twilio::Http::File sends the whole request body as multipart/form-data, with the file as one part and every other value as a part of its own. See "request" in Twilio::Http::Client.

Twilio's API descriptions don't say which values take a file, so the generated documentation describes them as text. Trusthub's compliance_registration_inquiries is the one that twilio-php uploads.

METHODS

new

my $file = Twilio::Http::File->new($file_name);
my $file = Twilio::Http::File->new($file_name, $contents, $content_type);

With only a name, the file is read from that path when the request is sent, and only its base name is sent. With $contents, a string of bytes or an open filehandle, $file_name is the name sent as it is. The contents are read once and kept, so a retried request sends the same file.

$content_type is optional. Without it, the part is sent as application/octet-stream.

get_file_name

Returns the name given to "new".

get_contents

Returns the contents given to "new", or nothing for a file read from a path.

get_content_type

Returns the content type given to "new", if any.

upload_name

Returns the name sent with the file.

bytes

Returns the bytes sent. Text with characters above 255 dies: encode it first, for example with Encode::encode('UTF-8', $text).

LICENSE

Copyright (c) 2026 Francisco Zarabozo. Released under the MIT License.