Page MenuHomePhabricator

Upload api does not work with GuzzleHttpRequest
Open, Needs TriagePublicBUG REPORT

Description

List of steps to reproduce (step by step, including full links if applicable):

  • Upload an image in the wiki
  • Create a new unit test with this code
$imagePage = new ImagePage( $title );

$requestData = [
    'action' => 'upload',
    'format' => 'json',
    'token' => $token,
    'filename' => $title->getText(),
    'ignorewarnings' => '1'
];

$file = $imagePage->getFile();
$be = $file->getRepo()->getBackend();
$localFile = $be->getLocalReference(
    [ 'src' => $file->getPath() ]
);
$requestData['file'] = new CurlFile( $localFile->getPath() );

$reqArgs = [
    'method' => 'POST',
    'timeout' => 'default',
    'postData' => $requestData
];

// Http::$httpEngine = 'curl'; // <=== Without this line this code does not work !
$req = MediaWikiServices::getInstance()->getHttpRequestFactory()
    ->create( $target . "/api.php", $options, __METHOD__ );

if ( array_key_exists( $target, $this->cookieJars ) ) {
    $req->setCookieJar( $this->cookieJars[$target] );
}

$status = $req->execute();

if ( $status->isOK() ) {
    $response = $req->getContent();
    return $response;
}

What happens?:
I have the error:

{"error":{"code":"missingparam","info":"One of the parameters \"filekey\", \"file\" and \"url\" is required.","*":"See http://..../w/api.php for API usage. Subscribe to the mediawiki-api-announce mailing list at &lt;https://lists.wikimedia.org/mailman/listinfo/mediawiki-api-announce&gt; for notice of API deprecations and breaking changes."}}

What should have happened instead?:
The message waited:

{"upload":{"result":"Success","filename":"...

Software version (if not a Wikimedia wiki), browser information, screenshots, other information, etc:
This code works in 1.35 with the line "Http::$httpEngine = 'curl';" but since 1.34, Http::$httpEngine is deprecated and GuzzleHttpRequest become the alone engine in Mediawiki (T214390).

When I comment the line "Http::$httpEngine = 'curl';", GuzzleHttpRequest executes this request but I have this error.

I don't know if it's a bug or a bad use of the GuzzleHttpRequest class.