Publish: 2016-04-19 | Modify: 2019-02-20
Typecho has a third-party plugin that uses the Qiniu SDK to automatically synchronize uploaded images to Qiniu. However, sometimes this plugin seems to have some issues, causing upload failures. I'm not sure if it's due to the Qiniu interface or the plugin itself. Here's a way to automatically replace Typecho article images with Qiniu URLs without using a plugin.
Skip the registration and real-name authentication process for Qiniu. First, create a bucket (space). I have already created a bucket named "typecho". Then, set up mirroring storage and fill in your blog address (http://faq.xiaoz.me/) as the mirror source. Finally, save the settings.
Find the test domain name assigned to your current Qiniu space or bind your own domain name. You will need it later. In the screenshot below, I have already bound a domain name "img.xiaoz.me" to the typecho space.
Find the post.php file in the theme directory of Typecho's article page. Find the following code:
<?php $this->content(); ?>
Replace it with:
<?php echo $str = str_replace("faq.xiaoz.me/usr/uploads","img.xiaoz.me/usr/uploads",$this->content); ?>
In the code above, "faq.xiaoz.me" is your blog's own domain name, and "img.xiaoz.me" is the domain name you bind to your Qiniu space or the test domain name assigned by Qiniu. This method works because Qiniu supports mirroring storage. After setting up the mirror source, when you visit the Qiniu URL, the corresponding file will be automatically fetched from the source address, without even using the SDK.
I come from China and I am a freelancer. I specialize in Linux operations, PHP, Golang, and front-end development. I have developed open-source projects such as Zdir, ImgURL, CCAA, and OneNav.