| @@ -2,8 +2,9 @@ | ||
| 2 | 2 | |
| 3 | 3 | namespace SyncBasalam\Services\Api; |
| 4 | 4 | |
| 5 | 5 | use SyncBasalam\Logger\Logger; |
| 6 | +use SyncBasalam\Services\MediaMimeType; | |
| 6 | 7 | |
| 7 | 8 | defined('ABSPATH') || exit; |
| 8 | 9 | |
| 9 | 10 | class FileUploadApiService |
| @@ -47,10 +48,9 @@ | ||
| 47 | 48 | } |
| 48 | 49 | |
| 49 | 50 | private function uploadWithCurl(string $url, string $filePath, array $data, array $headers, array $options): array |
| 50 | 51 | { |
| 51 | - $filetypeInfo = wp_check_filetype($filePath); | |
| 52 | - $mimeType = $filetypeInfo['type'] ?? 'application/octet-stream'; | |
| 52 | + $mimeType = MediaMimeType::detect($filePath); | |
| 53 | 53 | $fields = $data; |
| 54 | 54 | $fields['file'] = new \CURLFile($filePath, $mimeType, basename($filePath)); |
| 55 | 55 | $headerLines = []; |
| 56 | 56 | |
| @@ -208,10 +208,9 @@ | ||
| 208 | 208 | Logger::error('خطا در خواندن فایل با استفاده از file_get_contents: ' . $localFile); |
| 209 | 209 | return ''; |
| 210 | 210 | } |
| 211 | 211 | |
| 212 | - $filetypeInfo = wp_check_filetype($localFile); | |
| 213 | - $mimeType = $filetypeInfo['type'] ?? 'application/octet-stream'; | |
| 212 | + $mimeType = MediaMimeType::detect($localFile); | |
| 214 | 213 | |
| 215 | 214 | $payload .= '--' . $boundary . $eol; |
| 216 | 215 | $payload .= 'Content-Disposition: form-data; name="file"; filename="' . $filename . '"' . $eol; |
| 217 | 216 | $payload .= 'Content-Type: ' . $mimeType . $eol; |