Skip to content

Commit

Permalink
now works for google
Browse files Browse the repository at this point in the history
  • Loading branch information
James Michael DuPont authored and James Michael DuPont committed Sep 18, 2012
1 parent bf299d2 commit 3ac47e0
Showing 1 changed file with 39 additions and 18 deletions.
57 changes: 39 additions & 18 deletions lib/HTTP/Body/XFormsMultipart.pm
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package HTTP::Body::XFormsMultipart;
use strict;
use base 'HTTP::Body::MultiPart';
use bytes;

use Data::Dumper;
use IO::File;
use File::Temp 0.14;

Expand Down Expand Up @@ -44,13 +44,14 @@ sub init {
$self->SUPER::init(@_);
unless ( $self->content_type =~ /start=\"?\<?([^\"\>;,]+)\>?\"?/ ) {
my $content_type = $self->content_type;
my $content = $self->content;
warn "content_type:$content_type";
warn "content:$content";
Carp::croak( "Invalid boundary in content_type: '$content_type'" );
$self->{start} = "__NONE__";
# Carp::croak( "Invalid boundary in content_type: '$content_type'" );
}
else
{
#multipart/related; boundary=----------SFP876ns5iH3IQ3gRB2L4sYkgqXvTUcth0zo6mfBSuCkLGRmRR5TKbC
$self->{start} = $1;
}

$self->{start} = $1;

return $self;
}
Expand All @@ -75,22 +76,42 @@ set as the XForms:Model param if its content type is application/xml.
sub handler {
my ( $self, $part ) = @_;

my $contentid = $part->{headers}{'Content-ID'};
$contentid =~ s/^.*[\<\"]//;
$contentid =~ s/[\>\"].*$//;

if ( $contentid eq $self->start ) {
$part->{name} = 'XForms:Model';
my $cd= $part->{headers}{'Content-Disposition'};
#=> 'form-data; name="photo"; filename="DSCI0001.jpg"'
if ($cd) {
if ($part->{done}) {


if ($cd =~ /filename=\"([\"]+)\"/) {
$part->{filename} = $1;
}
if ($cd =~ /name=\"([\"]+)\"/) {
$part->{name} = $1;
}
$part->{name} = 'XForms:Model';
$self->body($part->{data});
}
return $self->SUPER::handler($part);

}
elsif ( defined $contentid ) {
$part->{name} = $contentid;
$part->{filename} = $contentid;
else
{
my $contentid = $part->{headers}{'Content-ID'} || "";
$contentid =~ s/^.*[\<\"]//;
$contentid =~ s/[\>\"].*$//;
if ( $contentid eq $self->start ) {
$part->{name} = 'XForms:Model';
if ($part->{done}) {
$self->body($part->{data});
}
}
elsif ( defined $contentid ) {
$part->{name} = $contentid;
$part->{filename} = $contentid;
}

return $self->SUPER::handler($part);
}

return $self->SUPER::handler($part);
}

=back
Expand Down

0 comments on commit 3ac47e0

Please sign in to comment.