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
$request
object. instance ofhttp::request
class, object similar interface do. return value response object. seehttp::request
,http::response
description of interface provided these classes.
from docs http::request
:
$r = http::request->new( $method, $uri, $header, $content )
constructs new
http::request
object describing request on object$uri
using method$method
.$method
argument must string.$uri
argument can either string, or reference uri object. optional$header
argument should referencehttp::headers
object or plain array reference of key/value pairs. optional$content
argument 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