How can I do multipart requests mith Mojo::UserAgent?

核能气质少年 提交于 2019-12-23 19:07:32

问题


I'd like to perform a multipart file upload to Google Drive as described here using a Mojo::UserAgent. I currently do it like this:

my $url = Mojo::URL->new('https://www.googleapis.com/upload/drive/v3/files');
$url->query({ fields => 'id,parents', 
              ocr => 'true', 
              ocrLanguage => 'de', 
              uploadType => 'multipart' });


my $tx = $ua->post($url,
                   json => { parents => [ '0ByFk4UawESNUX1Bwak1Ka1lwVE0' ] },
                   {
                       'Content-Type' => 'multipart/related',
                       'parents' => [ '0ByFk4UawESNUX1Bwak1Ka1lwVE0' ]
                   },
                   $content );

but it doesn't work.

I've managed authorization OK (omitted here) and simple file upload works fine. I just can't seem to do the multipart.

I've tried to make sense of the docs here - but to no avail, in the sense that the file gets uploaded OK, but the JSON part gets ignored, and the file gets uploaded in the root folder.

来源:https://stackoverflow.com/questions/46521633/how-can-i-do-multipart-requests-mith-mojouseragent

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!