How to upload image with name

Hello CF Community,

How can I name the images I upload? It does not take the file name as shown in the attachment, it saves it as “None”.

Which way do you upload images? can you show an example?

Hi,

I’m uploading with GuzzleHttp / PHP, Direct Upload End point.

$client = new Client();

        $accountID = config('app.cloudflare_images.account_id');
        $apiToken = config('app.cloudflare_images.api_token');

        $formData = [
            [
                'name' =>  'file',
                'contents' => $this->file,
            ],
            [
                'name' => 'metadata',
                'contents' => $this->metadata ,
            ],
            [
                'name' => 'requireSignedURLs',
                'contents' => 'false',
            ]
        ];

        $response = $client->request('POST',"https://api.cloudflare.com/client/v4/accounts/{$accountID}/images/v1",[
            'headers' => [
                'Authorization' => "Bearer {$apiToken}",
            ],
            'multipart' => $formData,
        ]);

        $responseBody = $response->getBody()->getContents();

        $data = json_decode($responseBody, true);

        $this->response = $data;

there’s filename multipart field you can use.

GuzzleHttp supports sending filename along with the file itself
https://docs.guzzlephp.org/en/stable/request-options.html#multipart

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.