typora图片自定义上传
网上的教程都是瞎超,我这个是自己写的,直接一个小脚本就自动插入图片乐,极其方便,只需要改一下自己的token就行了。
-
打开Typora,点击”文件” > “偏好设置”进入设置页面。
-
在左侧菜单栏中选择”图像”选项卡。
-
在”上传服务”部分,选择”自定义命令”。
-
在”上传命令”文本框中,输入您想要使用的自定义命令。php F:/WWW/php-library/TyporaUploadImage.php ${filename}
-
之后,每次在Typora中插入图片时,Typora就会自动使用您设置的自定义命令进行上传。
2.php上传代码:
这里如果你熟悉别的语言,也都是可以的。
<?php // Set the API endpoint URL $apiUrl = 'https://picui.cn/api/v1/upload'; // Set the API authorization header // https://picui.cn/user/tokens bruce $apiKey = '252|xxx'; $headers = array( 'Authorization:Bearer ' . $apiKey, 'Accept: application/json', 'Content-Type: multipart/form-data' ); // Check if there are any image paths provided if (count($argv) > 1) { echo "Upload Success:\n"; for ($i = 1; $i < count($argv); $i++) { $imagePath = $argv[$i]; $imageFileName = basename($imagePath); // Create the request data $data = array( 'file' => new CURLFile($imagePath, mime_content_type($imagePath), $imageFileName) ); // Initialize the cURL request $curl = curl_init($apiUrl); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, $data); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // Send the cURL request and get the response $response = curl_exec($curl); // Check for any cURL errors if (curl_errno($curl)) { echo 'cURL error (' . $i . '): ' . curl_error($curl) . "\n"; continue; } // Decode the JSON response $responseData = json_decode($response, true); // Check if the upload was successful if ($responseData['status']) { echo $responseData['data']['links']['url'] . "\n"; } else { echo 'Error (' . $i . '): ' . $responseData['message'] . "\n"; } // Close the cURL connection curl_close($curl); } } else { echo "Usage: php script.php <image_path1> <image_path2> ...\n"; } ?>
3.验证上传
参考官方链接:https://support.typora.io/Upload-Image/