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

Viewed 316

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.

0 Answers
Related