Executando verificação de segurança...
1

Upload de arquivos para o Vultr Object Storage

Bom dia.
Alguém já fez integração com a Vultr Object Storage?

Problema:
Está sinalizando como "enviado com sucesso", mas não envia o arquivo.

<?php

// Set your Vultr Object Storage credentials
$access_key = '';
$secret_key = '';
$bucket_name = '';

// Set the file path of the file you want to upload
$file_path = 'arquivo.png'; // 720x360 20.53KB

// Set the date and time of the request in UTC format
$date = gmdate('D, d M Y H:i:s T');

// Set the content type of the file you want to upload
$content_type = 'application/octet-stream'; // Correct content type for PNG images

// Set the URL of the file you want to upload
$file_url = 'https://sjc1.vultrobjects.com/' . $bucket_name . '/' . basename($file_path);

// Generate the string to sign
$string_to_sign = "PUT\n\n$content_type\n$date\nx-amz-date:$date\n/$bucket_name/" . basename($file_path);

// Generate the signature
$signature = base64_encode(hash_hmac('sha256', $string_to_sign, $secret_key, true));

// Initialize cURL
$ch = curl_init();

// Set the cURL options
curl_setopt($ch, CURLOPT_URL, $file_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_UPLOAD, true);
curl_setopt($ch, CURLOPT_INFILE, fopen($file_path, 'r'));
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($file_path));
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: ' . $content_type,
    'Authorization: AWS ' . $access_key . ':' . $signature,
    'x-amz-date: ' . $date,
));


// Execute the cURL request
$response = curl_exec($ch);

if ($response === false) {
    echo 'Erro ao fazer upload do arquivo: ' . curl_error($ch);
} else {
    echo 'Upload do arquivo bem-sucedido!';
}

// Close the cURL handle
curl_close($ch);
Carregando publicação patrocinada...