Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ RUN apt-get install -y \
RUN pip install gspread xlrd openpyxl lepl

RUN cd / && git clone https://github.com/MG-RAST/pipeline.git
RUN cp /pipeline/lib/StreamingUpload.pm /MG-RAST/site/lib/StreamingUpload.pm


RUN mkdir -p /sites/1/ && \
cd /sites/1/ && \
Expand Down
66 changes: 66 additions & 0 deletions src/MGRAST/lib/StreamingUpload.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package StreamingUpload;

use strict;
use warnings;
our $VERSION = '0.01';

use Carp ();
use HTTP::Request;

sub new {
my($class, $method, $uri, %args) = @_;

my $headers = $args{headers};
if ($headers) {
if (ref $headers eq 'HASH') {
$headers = +[ %{ $headers } ];
}
}

my $req = HTTP::Request->new($method, $uri, $headers);
_set_content($req, \%args);
$req;
}

sub _set_content {
my($req, $args) = @_;

if ($args->{content}) {
$req->content($args->{content});
} elsif ($args->{callback} && ref($args->{callback}) eq 'CODE') {
$req->content($args->{callback});
} elsif ($args->{path} || $args->{fh}) {
my $fh;
if ($args->{fh}) {
$fh = $args->{fh};
} else {
open $fh, '<', $args->{path} or Carp::croak "$args->{path}: $!";
}
my $chunk_size = $args->{chunk_size} || 4096;
$req->content(sub {
my $len = read($fh, my $buf, $chunk_size);
return unless $len;
return $buf;
});
}
}

sub slurp {
my(undef, $req) = @_;
my $content_ref = $req->content_ref;
$content_ref = ${ $content_ref } if ref ${ $content_ref };

my $content;
if (ref($content_ref) eq 'CODE') {
while (1) {
my $buf = $content_ref->();
last unless defined $buf;
$content .= $buf;
}
} else {
$content = ${ $content_ref };
}
$content;
}

1;
4 changes: 2 additions & 2 deletions src/MGRAST/lib/resources/inbox.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use warnings;
no warnings('once');

use POSIX qw(strftime);
use HTTP::Request::StreamingUpload;
use StreamingUpload;
use HTTP::Headers;
use LWP::UserAgent;
use File::Basename;
Expand Down Expand Up @@ -595,7 +595,7 @@ sub upload_file {
my $response = undef;
my $io_handle = $fh->handle;
eval {
my $post = HTTP::Request::StreamingUpload->new(
my $post = StreamingUpload->new(
POST => $Conf::shock_url.'/node',
fh => $io_handle,
headers => HTTP::Headers->new(
Expand Down