Pithub: How to create a new download via the Github v3 API

16 Jul 2011

Uploading a file to Github is a two step process: First you need to create a download resource. After that you can actually upload the file (to Amazon S3). All that is handled for you by Pithub. If you create new TRIAL release using Dist::Zilla, you can use Pithub to provide that file in the download section of your repository at Github. It would be handy to have this as a Dist::Zilla plugin.

The following script makes three assumptions: First: You created that file Pithub-0.01005-TRIAL.tar.gz already via Dist::Zilla, the script does not do that for you. Second: The script needs to be in the same folder as the tar.gz archive. You have an OAuth access token.

#!/usr/bin/env perl
use strict;
use warnings;
use Pithub::Repos::Downloads;

my $download = Pithub::Repos::Downloads->new(
    repo  => 'Pithub',
    token => 'my secret token',
    user  => 'plu',

my $result = $download->create(
    data => {
        name         => 'Pithub-0.01005-TRIAL.tar.gz',
        size         => ( stat('Pithub-0.01005-TRIAL.tar.gz') )[7],
        description  => 'Pithub v0.01005 TRIAL',
        content_type => 'application/x-gzip',

if ( $result->success ) {
    my $upload = $download->upload(
        result => $result,
        file   => 'Pithub-0.01005-TRIAL.tar.gz',
    if ( $upload->is_success ) {
        printf "The file has been uploaded succesfully and is now available at: %s\n", $result->content->{html_url};

Here are some links that might help you: