We're updating the issue view to help you get more done.Learn more

File upload: get return code 200 and the return is empty

Original report: https://forum.mattermost.org/t/api-upload-file-not-uploading/6776

Steps to reproduce
Version 5.7.0.
Laravel PHP curl upload a file via API request:

$curl = curl_init();

curl_setopt_array($curl, array(
CURLOPT_URL => env('MATTERMOST_URL')."/api/v4/files?channel_id=".$channel_id."&filename=".$destinationPath.'/'.$name,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => array('files' => $destinationPath.'/'.$name, 'channel_id' => $channel_id),
CURLOPT_HTTPHEADER => array(
"Authorization: Bearer ".$_COOKIE,
"Content-Type: multipart/form-data"
),
));

$response = curl_exec($curl);
$err = curl_error($curl);

Expected behavior
Sending the file path (which has already been temporarily saved in Laravel storage) and the channel through cURL, should receive the API return as follows:
{
“file_infos”: [

{ “id”: “string”, “user_id”: “string”, “post_id”: “string”, “create_at”: 0, “update_at”: 0, “delete_at”: 0, “name”: “string”, “extension”: “string”, “size”: 0, “mime_type”: “string”, “width”: 0, “height”: 0, “has_preview_image”: true }

],
“client_ids”: [
“string”
]
}

Observed behavior
Receiving return with empty fields

{“file_infos”: [], “client_ids”: []}

Status

Mana

2

Assignee

Lev Brouk

Reporter

Amy Blais

Fix versions

Mattermost Team

Extensibility

Labels