Mattermost Peer-to-Peer Forum

API Upload File not uploading


#1

Summary

I am sending files to upload, I get return code 200, but the return is empty.

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['MMAUTHTOKEN'],
                    "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”: []}


#2

Hi @paulus,

Wondering if this earlier thread might help: [SOLVED] Uploading an image with api v. 4 not working. If not, we’ll continue to troubleshoot.


#3

Hello, amy

Thanks for the help.
I had seen this topic before, but it did not help me. There is an error situation there. I do not get error (like status code 403 or similar). My request returns successfully, but without the submitted file information.


#4

Hi @paulus,

From a community member:

Would you be able to provide a curl command line to reproduce the issue? How did you confirm that the file you want to upload is available? (More a FYI: pr-mattermost-server-9835 )


#5

Hi @amy.blais

I’m using cURL via PHP, but using just curl, the command is that:

curl -F 'files=/var/www/html/public/uploads/chat/p7nxd4pe8fgn9yyzrrujwuadww_user_er.PNG' \
-F 'channel_id=p7nxd4pe8fgn9yyzrrujwuadww' \
--header 'authorization: Bearer yiiw7i3r13nodm9tke1exppgne'
http://192.168.240.59:8065/api/v4/files 

The file exists in the directory and has permissions to read and execute (plus write for file owner).

Thanks


#6

Hi @paulus,

Our developers said this sounds like a bug so I opened a bug ticket: https://mattermost.atlassian.net/browse/MM-14499.


#7

Thanks so much, @amy.blais