Skip to content

Instantly share code, notes, and snippets.

@jesteves
Last active July 26, 2021 16:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jesteves/4ad34351159b079a106aeac960149e4c to your computer and use it in GitHub Desktop.
Save jesteves/4ad34351159b079a106aeac960149e4c to your computer and use it in GitHub Desktop.
Upload to Zoho WorkDrive - Perl snippet
# upload_snippet.pl
#
# Upload to Zoho WorkDrive from Perl.
#
# -- Julián Esteves / July, 2021
#
use strict;
use warnings;
use LWP::UserAgent;
use HTTP::Request;
use JSON::PP 'decode_json';
my $ZOHO_API_ENDPOINT_BASE = 'https://workdrive.zoho.com'; # or .eu, etc.
my $file_name = 'some.file';
my $file_path = '/path/to/some.file';
my $parent_folder_id = '#####################################';
my $access_token =
'1000.################################.################################';
my $ua = LWP::UserAgent->new;
my $response = $ua->post(
"$ZOHO_API_ENDPOINT_BASE/api/v1/upload",
Content_Type => 'form-data',
Content => [
filename => $file_name,
parent_id => $parent_folder_id,
'override-name-exist' => 'true',
content => [
$file_path, $file_name,
'Content-Type' => 'application/octet-stream'
]
],
Authorization => "Zoho-oauthtoken $access_token"
);
if ( $response->is_success ) {
my $response_hashref = decode_json $response->decoded_content;
my $permalink = $response_hashref->{data}->[0]->{attributes}->{Permalink};
print "uploaded!\n" . "permalink: $permalink\n";
}
else {
my ( $status_line, $decoded_content ) =
( $response->status_line, $response->decoded_content );
print "could not upload!\n" . "$status_line\n" . "$decoded_content\n";
}
1; # PBP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment