postgresql - Implement Tapatalk image upload in Perl -
i writing tapatalk plugin using perl. have gone through tapatalk documentation upload images tapatalk app https://tapatalk.com/api/api_section.php?id=8#upload.php
as per documentation, have upload.cgi @ root of plugin directory called when image upload tried tapatalk app. have method name, forumid, attachment image name in upload.cgi.
but confuse how handle display uploaded image in tapatalk app after successful upload. how input parameters of upload.cgi handled. how upload details posted upload.cgi
i have posted form details below
my $req = post '$upload_url', content_type => 'form-data', content => [ method_name => 'upload_attach', forum_id => $forumid, "attachment[]" => [ undef, $filename, 'content-type' => 'image/jpeg', ], ]; $ua = lwp::useragent->new(); $response = $ua->request($req); but have not work. please me, if have done before. if have sample code regarding image upload, please share it.
at moment, script doing nothing because $req set code melange perl not know how interpret:
my $req = post '$upload_url', content_type => 'form-data', content => [ method_name => 'upload_attach', forum_id => $forumid, "attachment[]" => [ undef, $filename, 'content-type' => 'image/jpeg', ], ]; if want use $ua->request(), need create http::request object. docs lwp::useragent request:
$ua->request( $request )this method dispatch given
$requestobject. instance ofhttp::requestclass, object similar interface do. return value response object. seehttp::request,http::responsedescription of interface provided these classes.
from docs http::request:
$r = http::request->new( $method, $uri, $header, $content )constructs new
http::requestobject describing request on object$uriusing method$method.$methodargument must string.$uriargument can either string, or reference uri object. optional$headerargument should referencehttp::headersobject or plain array reference of key/value pairs. optional$contentargument should string of bytes.
so, reformatting request, following:
my $req = http::request->new('post', $upload_url, [ content_type => 'form-data' ], content => [ method_name => 'upload_attach', forum_id => $forumid, "attachment[]" => [ undef, 'this.jpg', 'content-type' => 'image/jpeg', ], ]); plug script:
use strict; use warnings; use lwp::useragent; $upload_url = 'http://example.com'; $forum_id = '1a2b3c4d5e'; $ua = lwp::useragent->new(); $req = http::request->new('post', $upload_url, [ content_type => 'form-data' ], content => [ method_name => 'upload_attach', forum_id => $forum_id, "attachment[]" => [ undef, 'this.jpg', 'content-type' => 'image/jpeg', ], ]); $response = $ua->request($req); if ($response->is_success) { # whatever $response->decoded_content } else { print stderr "post failed: " . $response->status_line . "\n"; } you can see raw http response using $response->as_string.
hope helps little!
Comments
Post a Comment