Permalink
Browse files

Enable PUT methods to work on S3Image by splitting out upload code fr…

…om object init code
  • Loading branch information...
perlDreamer committed Sep 28, 2018
1 parent 1a0286c commit 4eb8f2a7d3d376fb15fe40d71990968987cd8919
Showing with 7 additions and 2 deletions.
  1. +7 −2 lib/Wing/Role/Result/S3Image.pm
@@ -90,8 +90,13 @@ sub initialize {
my $self = Wing->db->resultset($class)->new({});
$self->id(Data::GUID->new->as_string); # want the id and haven't inserted yet
$self->image_relationship_id($related_id);
$self->filename($self->fix_filename($filename));
$self->resize_image($path) unless $noresize;
$self->handle_upload($filename, $path);
}
sub handle_upload {
my ($self, $filename, $path) = @_;
$self->filename($self->fix_filename($filename));
my $info = Image::ExifTool::ImageInfo($path, [], { Exclude => ['FileName','Directory','FilePermissions']});
my $meta;
while ( my ($key, $value) = each %{$info}) {
@@ -105,7 +110,7 @@ sub initialize {
my $thumbnail = $self->generate_thumbnail($path);
$self->upload_file_to_s3($path, $self->filename);
$self->upload_file_to_s3($thumbnail, 'thumbnail'.$self->extension);
$self->insert;
$self->touch;
return $self;
}

0 comments on commit 4eb8f2a

Please sign in to comment.