Perl - 无法通过API发送图像 - 抛出错误无法打开文件名/usr/share/perl5/LWP/UserAgent.pm第419行没有这样的文件或目录

时间:2017-09-23 01:14:54

标签: perl api

use LWP::UserAgent;
use File::Slurp;
use warnings;
use strict;

my $baseUrl     = 'xxxxx';
my $accessToken = 'xxxxx';

my $shelfGuid = 'xxxxx';
my $url         = $baseUrl . 'yyyy';
my $sourceFile  = '/home/example.png';
my $destFile    = 'example.png';
my $ua          = LWP::UserAgent->new;
$ua->default_header( 'authorization' => "bearer $accessToken" );
my $response    = $ua->post($url,
   'Content_Type' => 'form-data',
   Content => [
      file => [
         name => $sourceFile,
         filename => $destFile,
         Content_Type => 'image/png'
      ],
      model => { ShelfGuid => $shelfGuid }
   ]
);

print $response;

获取此错误 - 无法打开文件名:/usr/share/perl5/LWP/UserAgent.pm第419行没有此类文件或目录。

尝试了一整天没有任何进展。非常感谢。谢谢。

1 个答案:

答案 0 :(得分:0)

它正在尝试打开名为return <div> <Dialog title="Login" actions={actions} modal={false} open={this.props.open} onRequestClose={this.handleClose}> <div className="loadingRoot"> TEST TEST TEST TEST TEST TESTTEST TEST TESTTEST TEST TESTTEST TEST TESTTEST TEST TESTTEST TEST TESTTEST TEST TESTTEST TEST TESTTEST TEST TESTTEST TEST TESTTEST TEST TESTTEST TEST TESTTEST TEST TESTTEST TEST TESTTEST TEST TESTTEST TEST TESTTEST TEST TESTTEST TEST TESTTEST TEST TEST </div> <div> <TextField floatingLabelText='username' name='username' onChange={this.handleTextFieldChange} /><br /> <TextField floatingLabelText='password' name='password' onChange={this.handleTextFieldChange} /> </div> </Dialog> </div>; 的文件。取代

name

file => [ name => $sourceFile, filename => $destFile, Content_Type => 'image/png' ]

不相关,其他字段的值也看起来不对。

file => [ $sourceFile, $destFile, Content_Type => 'image/png' ]

值应为字符串,或文件上载的数组引用,但不是散列引用。