Loading ...
Sorry, an error occurred while loading the content.

Idiots Guide to Mime Attachments and SOAPLight

Expand Messages
  • Will Fawcett
    To Start, I am a newbie to SOAP WSDL and Sadly even OO-Perl, So I realize I am at a extreme disadvantage. But I really need to get a Soap Client Sending and
    Message 1 of 2 , Nov 10, 2004
    • 0 Attachment
      To Start, I am a newbie to SOAP WSDL and Sadly even OO-Perl, So I
      realize I am at a extreme disadvantage. But I really need to get a
      Soap Client Sending and Attachment to a server. Sadly I can't find
      any working examples to help me out. Majordojo is a great resource
      but I fear that it expects a higher understanding of Perl and SOAP
      than I currently possess. I have some very basic questions, please
      don't laugh. I really just want to learn.

      #!/usr/bin/perl -w
      use SOAP::Lite;
      use MIME::Entity;

      $namespace = "my namespace";
      $uriLoc = "script location";

      my $ent = build MIME::Entity
      Type => "image/gif",
      Encoding => "base64",
      Path => "blah.gif",
      Filename => "blah.gif",
      Disposition => "attachment";

      my $som = SOAP::Lite
      ->readable(1)
      ->uri($namespace)
      ->parts([$ent])
      ->proxy($uriLoc)
      ->AttachmentHandler(SOAP::Data->name("foo" => "bar"));

      As you can see it is exactly the code found on Brynes Website, my
      question is that what is the reason for that last line "SOAP::Data-
      >name("foo"=>"bar)); ?? I know that it will serialize as
      <foo>bar</foo> but what do I need on the server to accept that, and
      why can't I just leave it out?

      My Server currently looks like this:

      #!/usr/bin/perl -w
      use SOAP::Transport::HTTP;
      use MIME::Parser;

      print $MIME::Parser::VERSION;

      SOAP::Transport::HTTP::CGI
      -> dispatch_to('lifestyle')
      -> handle;

      package lifestyle;
      use SOAP::Lite;
      use MIME::Entity;
      use vars qw(@ISA);
      @ISA= qw(SOAP::Server::Parameters);

      sub AttachmentHandler{
      my $self = shift; # this is the package declaration aka lifestyle
      my $envelope = pop;#this is the value of the SOAP::Data::Name
      (id=>value)
      my $STRING = $envelope->valueof(`[1]');
      print STDERR $STRING;

      Presently I get an error:
      soap:Server, Can't locate object method "valueof" via package "bar"
      (perhaps you forgot to load "bar"?)
      at /home/demo/bin/SendBinData.cgi line 20.

      Based off what I am reading I should be able to treat envelope as a
      SOAP::SOM object, so valueof should be valid, am I wrong in that
      assessment?

      What I really want is to take the file that I am sending from the
      client, decode it and save it to disk. If any one can point me to a
      working complete simple example of that It would be very helpful.

      And if anyone has found any resources out there for sending
      attachments, please send me a link, from what I can tell, not many
      people are using Soaplite to send attachments.

      Thanks again for everyone's help, this a great group
      -Will
    • Duncan Cameron
      ... For your purposes, if you do not want to pass any data from the client to the server then you can leave that out. ... It looks like the inheritance from
      Message 2 of 2 , Nov 11, 2004
      • 0 Attachment
        At 2004-11-11, 06:44:01 Will Fawcett <nailism23@...> wrote:

        >To Start, I am a newbie to SOAP WSDL and Sadly even OO-Perl, So I
        >realize I am at a extreme disadvantage. But I really need to get a
        >Soap Client Sending and Attachment to a server. Sadly I can't find
        >any working examples to help me out. Majordojo is a great resource
        >but I fear that it expects a higher understanding of Perl and SOAP
        >than I currently possess. I have some very basic questions, please
        >don't laugh. I really just want to learn.
        >
        >#!/usr/bin/perl -w
        >use SOAP::Lite;
        >use MIME::Entity;
        >
        >$namespace = "my namespace";
        >$uriLoc = "script location";
        >
        >my $ent = build MIME::Entity
        > Type => "image/gif",
        > Encoding => "base64",
        > Path => "blah.gif",
        > Filename => "blah.gif",
        > Disposition => "attachment";
        >
        >my $som = SOAP::Lite
        > ->readable(1)
        > ->uri($namespace)
        > ->parts([$ent])
        > ->proxy($uriLoc)
        > ->AttachmentHandler(SOAP::Data->name("foo" => "bar"));
        >
        >As you can see it is exactly the code found on Brynes Website, my
        >question is that what is the reason for that last line "SOAP::Data-
        >>name("foo"=>"bar)); ?? I know that it will serialize as
        ><foo>bar</foo> but what do I need on the server to accept that, and
        >why can't I just leave it out?
        >
        For your purposes, if you do not want to pass any data from the client
        to the server then you can leave that out.

        >My Server currently looks like this:
        >
        >#!/usr/bin/perl -w
        >use SOAP::Transport::HTTP;
        >use MIME::Parser;
        >
        >print $MIME::Parser::VERSION;
        >
        >SOAP::Transport::HTTP::CGI
        > -> dispatch_to('lifestyle')
        > -> handle;
        >
        >package lifestyle;
        > use SOAP::Lite;
        > use MIME::Entity;
        > use vars qw(@ISA);
        > @ISA= qw(SOAP::Server::Parameters);
        >
        >sub AttachmentHandler{
        > my $self = shift; # this is the package declaration aka lifestyle
        > my $envelope = pop;#this is the value of the SOAP::Data::Name
        >(id=>value)
        > my $STRING = $envelope->valueof(`[1]');
        > print STDERR $STRING;
        >
        >Presently I get an error:
        >soap:Server, Can't locate object method "valueof" via package "bar"
        >(perhaps you forgot to load "bar"?)
        >at /home/demo/bin/SendBinData.cgi line 20.
        >
        It looks like the inheritance from SOAP::Server::Parameters isn't
        taking effect because the lifestyle package @ISA has not been assigned
        to - remember that it is a run-time assignment, not compile-time.

        Three choices

        1) move the lifestyle package to a separate source file and change the
        dispatch_to() to include the directory

        2) move the lifestyle code to the start of this file, and then switch
        back to the main package

        package lifestyle;

        ...

        package main;

        ...

        3) wrap the lifestyle package in a BEGIN block so that it gets executed
        first

        But you don't really want to be looking at the envelope anyway. The
        attachments are automatically decoded for you.

        The server code is as simple as this:
        soap.cgi
        =====

        use strict;
        use SOAP::Transport::HTTP;

        my $packager = SOAP::Packager::MIME->new;
        $packager->initialize_parser;
        $packager->parser->output_to_core(0);
        $packager->parser->output_dir('./Attachments');

        SOAP::Transport::HTTP::CGI
        -> dispatch_to('.')
        ->packager($packager)
        -> handle;

        put your application code in its own source file

        lifestyle.pm
        =======

        use strict;
        package lifestyle;

        use SOAP::Lite;
        use vars qw(@ISA);
        @ISA= qw(SOAP::Server::Parameters);

        sub AttachmentHandler{
        my $self = shift;
        my $envelope = pop;
        foreach my $part (@{$envelope->parts}) {
        print STDERR "attachment found! (".ref($part).")\n";
        $part->dump_skeleton(*STDERR);
        }
        return "OK";
        }
        1;

        Each attachment and the soap envelope will now be saved automatically
        in the Attachments subdirectory.

        Try this and see how you get on.

        Duncan
      Your message has been successfully submitted and would be delivered to recipients shortly.