英文原版Ghost如何使用七牛云

旧博客迁移文章,内容可能已失去价值,仅为留念,做了简单重新排版,勉强可看。

小博搭建于腾讯云,享受学生优惠,带宽1M,对于大的图片资源还是有点吃不消,遂决定将图片资源迁移至七牛,减轻云主机负担。

Ghost 版本:0.7.8 Ghost 中文版本:0.7.4 1. 注册为七牛会员。七牛用户,每月有如下优惠: >10GB 永久免费存储空间
每月 10GB 下载流量
每月 10万 次PUT请求
每月 100万 次GET请求
每月 750 小时自定义数据处理实例免费使用时间
每月MPS配额 20元

10G流量差不多够我用了。

2.创建存储空间(假设空间名为:funnyang),点右上角的账号名->账户信息->密钥管理,得到AccessKey/SecretKey。

3.安装七牛的nodejs SDK

cd ghost-path  //ghost-path指ghost的安装目录
npm install qiniu --production

4.修改ghost-path/package.json

...
"dependencies": {
    ...
    //添加,版本根据你安装的SDK版本填写
    "qiniu": "6.1.9" 

5.ghost-path/core/server/storage/index.js 替换成以下内容:(也可直接替换中文版的相同文件)

var errors  = require('../errors'),
config  = require('../config'),
storage = {};

function getStorage(storageChoice) {
    storageChoice = (config.storage && config.storage.provider) || 'local-file-store';
    if (storage[storageChoice]) {
        return storage[storageChoice];
    }
    try {
        storage[storageChoice] = require('./' + storageChoice);
    } catch (e) {
        errors.logError(e);
    }
    storage[storageChoice] = new storage[storageChoice]();
    return storage[storageChoice];
}

module.exports.getStorage = getStorage;

6.修改ghost-path/config.js,对照位置修改,实在看不明白,也可以看中文版的config.js修改。

config = {
    production: {

        ···

          server: {
               host: '127.0.0.1',
               port: '2368'
           },
          storage: {
               provider: 'qiniu',
               bucketname: 'funnyang', //即空间名
               ACCESS_KEY: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
               SECRET_KEY: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
               root: '/image/', //指保存文件的路径
               prefix: 'http://your-bucket-name.qiniudn.com' //空间的链接
          }

}

7.修改ghost-path/core/server/api/configuration.js

function getValidKeys() {
    var validKeys = {
        ...
        //添加
        storage: (config.storage && config.storage.provider) || 'local-file-store'

8.复制ghost-path/core/server/storage/qiniu.js到英文版相应位置。

大功告成,上传图片试一试吧!看是否上传到了七牛。

本文链接:参与评论 »

--EOF--

提醒:本文最后更新于 3130 天前,文中所描述的信息可能已发生改变,请谨慎使用。

Comments