App-ggdrv

 view release on metacpan or  search on metacpan

lib/App/ggdrv/update.pm  view on Meta::CPAN

  my $URI = URI->new( $GOOGLE_DRIVE_UPLOAD_API . $_[1] );
  $URI->query_param( uploadType => 'multipart' );
  my $ua  = LWP::UserAgent->new;
  my $res = $ua->request(
    PATCH $URI,
    'Content-Type' => 'multipart/form-data',
    Authorization  => "Bearer $atoken" ,
    Content    => [
      metadata => [
        undef, undef, # undef => undef と書くことは出来るだろうか?
        'Content-Type' => 'application/json;charset=UTF-8',
        'Content' => encode_json( {} ) #name=>'temp.txt', mimeType=>'text/plain', parents  => ['10_33chars_in_total'], id => $target_fileid},
      ],
      file => [ $_[0] ] #["./anotherName.txt"],
    ],
  );
  print $res->code . "\n";
  print $res->content . "\n";
}


lib/App/ggdrv/upload.pm  view on Meta::CPAN


sub f_each ( $ ) { 
  binmode STDOUT, ":utf8";
  my $mimeType = $o{m} ; 
  my $ej1 = encode_json { name => $_[0] , mimeType => $mimeType , $o{f} ne q[] ? ( parents  => [ $o{f} ] ): () } ;
  my $res = LWP::UserAgent -> new -> request (
    POST $GOOGLE_DRIVE_UPLOAD_API ,
    'Content-Type' => 'multipart/form-data' ,
    Authorization =>  "Bearer $atoken" ,
    Content => [
      metadata => [ undef, undef , 'Content-Type' => 'application/json;charset=UTF-8' , 'Content' => $ej1 ] ,
      file => [ $_[0] ] ,
    ] ,
    ) ;
  my $j = decode_json ( $res->content ) ; 
  say join "\t" , map { $_ // 'undef' } $res->code , $j->{id}, $j->{name}, $j->{mimeType} , $j->{kind} ; 
}

=encoding utf8

=head1



( run in 0.282 second using v1.01-cache-2.11-cpan-4d50c553e7e )