V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
huntzhan
V2EX  ›  Python

将图片自动上传到 GitHub, 返回图片 URL

  •  
  •   huntzhan ·
    huntzhan · 2016-08-14 12:35:29 +08:00 · 13823 次点击
    这是一个创建于 2802 天前的主题,其中的信息可能已经有所发展或是发生改变。
    第 1 条附言  ·  2016-08-17 23:32:53 +08:00
    GitHub 的官方回复, 并不构成 Abuse.

    > Thanks for your question! We've reviewed your project and, in addition to uploading files, it appears to assist in generating rawgit URLs. Is that correct?
    >
    > If that's the case, your project doesn't appear to violate GitHub's Terms of Service, though you may want to check in with the owner of rawgit if you haven't already done so.
    >
    > Of course, any individual who decided to use your code would be responsible for making sure their usage and content didn't violate our Terms.
    >
    > Please let me know if you have any other questions.
    第 2 条附言  ·  2016-08-17 23:33:53 +08:00
    另外, 目前项目已经支持七牛的对象存储, 这让有洁癖的用户也可以使用了.
    78 条回复    2018-01-11 12:12:11 +08:00
    xiahei
        1
    xiahei  
       2016-08-14 12:42:24 +08:00 via Android   ❤️ 12
    GitHub 不是用来做图床的。为何要这样……
    v1024
        2
    v1024  
       2016-08-14 13:24:59 +08:00
    一段简单的 shell , cp 图片到 git 仓库 , 自动 add+commit+push ,效果一样,不懂楼主搞这么复杂干啥,连 travis-ci 都用上了。。
    aprikyblue
        3
    aprikyblue  
       2016-08-14 13:35:05 +08:00 via Android
    所以 lz 你有多闲。。
    slixurd
        4
    slixurd  
       2016-08-14 13:43:44 +08:00
    少年哈哈哈哈哈哈....
    huntzhan
        5
    huntzhan  
    OP
       2016-08-14 14:05:19 +08:00
    @slixurd (远目)
    huntzhan
        6
    huntzhan  
    OP
       2016-08-14 14:06:12 +08:00
    @xiahei 我觉得挺好的, GitHub 本身的 CDN 好像速度还可以的样子 (
    huntzhan
        7
    huntzhan  
    OP
       2016-08-14 14:07:56 +08:00
    @v1024 的确不是什么复杂的东西, 但是做一层抽象总是好的, 反正我自己用得挺爽
    huntzhan
        8
    huntzhan  
    OP
       2016-08-14 14:09:12 +08:00
    @v1024 而且 travis-ci 这种东西这么简单又不用钱, 干嘛不用
    huntzhan
        9
    huntzhan  
    OP
       2016-08-14 14:10:11 +08:00
    @v1024 如果不是 PyPI 的版本管理太扭曲, 我还打算把自动发布也集成到 TravisCI 里, 每次 commit 过了 testcases 就自动 push 个版本...
    vitovan
        10
    vitovan  
       2016-08-14 14:17:29 +08:00   ❤️ 1
    建议把最终地址换成这个:

    https://rawgit.com/
    huntzhan
        11
    huntzhan  
    OP
       2016-08-14 14:22:10 +08:00
    @vitovan thanks!
    huntzhan
        12
    huntzhan  
    OP
       2016-08-14 14:27:26 +08:00
    @vitovan 已经换了
    majinjing3
        13
    majinjing3  
       2016-08-14 14:39:39 +08:00 via Android
    如果直接在产品中使用,会对 github 完成形象么?
    huntzhan
        14
    huntzhan  
    OP
       2016-08-14 14:41:40 +08:00
    @majinjing3 "会对 github 完成形象么?" 没看懂...
    majinjing3
        15
    majinjing3  
       2016-08-14 14:47:30 +08:00
    @huntzhan 如果直接在产品中使用,会对 github 造成影响么?打错字了, sorry !
    inoris
        16
    inoris  
       2016-08-14 14:47:59 +08:00   ❤️ 1
    @majinjing3 @huntzhan 我猜是「造成影响」,九宫格输入法的锅 :)。
    majinjing3
        17
    majinjing3  
       2016-08-14 14:48:56 +08:00
    @huntzhan 建议加个自定义上传分支的配置,不仅仅是 master
    huntzhan
        18
    huntzhan  
    OP
       2016-08-14 14:49:16 +08:00   ❤️ 1
    @majinjing3 不会吧, 有 CDN 顶着
    huntzhan
        19
    huntzhan  
    OP
       2016-08-14 14:49:40 +08:00
    @inoris XD
    majinjing3
        20
    majinjing3  
       2016-08-14 14:50:02 +08:00
    @inoris 真聪明,佩服,佩服!
    inoris
        21
    inoris  
       2016-08-14 14:50:20 +08:00
    看起来是开一个 repo 用来放图的,感觉不太友好。 GitHub 自己有一个图床接口,在 Issues 页里可以拖拽图片上传,接口是 https://github.com/upload/policies/assets ,不妨试试?
    huntzhan
        22
    huntzhan  
    OP
       2016-08-14 15:52:56 +08:00
    @majinjing3 已经加上了, 支持自定义 branch 与 path.
    huntzhan
        23
    huntzhan  
    OP
       2016-08-14 15:55:20 +08:00
    @inoris 你说的是 https://developer.github.com/v3/repos/releases/ 这个接口吧? 似乎这个接口也不适合用来做这个事情. 之前我打算用 issue 的自动拖图片上传的接口, 调研的结论是 GitHub 没有开放这个接口, 所以才直接用 contents 的 API 的.
    hellopython
        24
    hellopython  
       2016-08-14 16:46:44 +08:00
    Example of .img2url.yml:

    token: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    user: img2url-testing
    repo: img2url-testing-travisci
    proxies:
    https: socks5://127.0.0.1:1080
    Required fields:

    token: Personal access tokens of your GitHub account. If you don't have one, click "Generate new token" and select the "repo" scope, then record the generated token.
    user: Account of GitHub.
    repo: The repository to store images.

    这个怎么填写啊?
    7sDream
        25
    7sDream  
       2016-08-14 17:06:58 +08:00   ❤️ 6
    感觉吧,并不是很道德,毕竟 Github 是为了合作码代码,而不是作为网盘或图床。

    Github 使用协议的 General Conditions 第 12 条: If your bandwidth usage significantly exceeds the average bandwidth usage (as determined solely by GitHub) of other GitHub customers, we reserve the right to immediately disable your account or throttle your file hosting until you can reduce your bandwidth consumption.

    所以还是注意下吧。

    如果有人去 https://github.com/contact/report-abuse 报告滥用的话可能会被封的。

    善意提醒一下。
    huntzhan
        26
    huntzhan  
    OP
       2016-08-14 17:11:11 +08:00
    @7sDream 十分感谢, 之前没有注意到这一点. 我看下是否有解决方案...
    huntzhan
        27
    huntzhan  
    OP
       2016-08-14 17:13:22 +08:00
    @hellopython 在 HOME 下面创建一个 `.img2url.yml`, 然后按照 YAML 的语法写就可以了. 直接把 example 复制过去, 改下 `token`, `user`, `repo` 的值就可以用了.
    we000
        28
    we000  
       2016-08-14 17:23:47 +08:00
    @huntzhan 解决方案就是删除项目, 确实是 abuse 了
    huntzhan
        29
    huntzhan  
    OP
       2016-08-14 17:27:17 +08:00
    @7sDream https://github.com/rgrove/rawgit/wiki/Frequently-Asked-Questions#what-will-happen-if-i-send-large-amounts-of-traffic-to-a-rawgitcom-development-url
    我觉得已经套上了一层 CDN, bandwidth 已经不是问题了. 我猜这个跟使用 GitHub host personal static website 是一个性质的, I'm not sure.
    huntzhan
        30
    huntzhan  
    OP
       2016-08-14 17:27:28 +08:00
    @we000 同上
    20150517
        31
    20150517  
       2016-08-14 17:36:48 +08:00
    我之前看到有人开发了个类似的,不过是上床新浪微博图床的,还是用那个比较好,github 国内毕竟慢
    hellopython
        32
    hellopython  
       2016-08-14 17:38:53 +08:00
    @huntzhan 好的,谢谢,我是在 windows7 版本装的 python2.7 ,然后 pip 装的 img2url ,在 DOS 界面无法成功上传
    .img2url.yml 内容
    token 填的新建的
    user Github 名字
    repo 填写的新建的 photos
    huntzhan
        33
    huntzhan  
    OP
       2016-08-14 17:43:54 +08:00
    @hellopython ...十分抱歉, 我手上没有 windows 的系统, 我试下用虚拟机测试一下. 字段的描述是对的.
    cszhiyue
        34
    cszhiyue  
       2016-08-14 18:08:23 +08:00
    @huntzhan 确实是滥用了。建议楼主删除这个 repos 。
    XhstormR
        35
    XhstormR  
       2016-08-14 18:09:05 +08:00
    github 仓库大小是有限的,不过不知道是多大。
    cszhiyue
        36
    cszhiyue  
       2016-08-14 18:18:35 +08:00
    llbbzh
        37
    llbbzh  
       2016-08-14 19:55:47 +08:00
    这就是典型的**滥用**啊……

    为何不用新浪微博呢,微博就是拿来分享图片的
    ZE3kr
        38
    ZE3kr  
       2016-08-14 19:58:25 +08:00 via iPhone
    @7sDream 其实 GitHub 有 Git LFS ,随便存多大视频、图片,但是要交钱哦。 @XhstormR
    ZE3kr
        39
    ZE3kr  
       2016-08-14 20:00:25 +08:00 via iPhone
    https://help.github.com/articles/billing-plans-for-git-large-file-storage/ 用这个就不算滥用了吧,要是有需要就是要用 Git 管理那些图片呢,还是很有用的。
    huntzhan
        40
    huntzhan  
    OP
       2016-08-14 20:10:35 +08:00
    @llbbzh ...我发邮件去问下
    huntzhan
        41
    huntzhan  
    OP
       2016-08-14 20:48:46 +08:00   ❤️ 4
    我发邮件了, 如果 GitHub 认为这个是 Abuse 我立马删项目
    XhstormR
        42
    XhstormR  
       2016-08-14 21:01:08 +08:00
    @cszhiyue 所以个人免费仓库限额 1 G 吗?
    xmoiduts
        43
    xmoiduts  
       2016-08-14 22:00:11 +08:00 via Android
    给 github 充值就不算滥用,
    流量&存储包: 50GB 存储加 50GB 流量,$5/月,无限叠加。
    只要充够了钱,你就能变得更强。
    Seita
        44
    Seita  
       2016-08-14 22:01:41 +08:00
    @huntzhan 你收到的回复一定是让你不要这样做
    srlp
        45
    srlp  
       2016-08-14 22:56:29 +08:00
    讲道理,应该使用 imgur
    huntzhan
        46
    huntzhan  
    OP
       2016-08-14 22:59:44 +08:00
    @srlp 调研的时候试过了, 非常慢. 上传一个 1 Mb 左右的文件用了十分钟.
    hinkal
        47
    hinkal  
       2016-08-14 23:04:54 +08:00
    可怕,这算垃圾项目了吗? [有些事技术其实不难为什么大家都不去做?]
    koalli
        48
    koalli  
       2016-08-14 23:08:01 +08:00
    微博是个好图床...
    huntzhan
        49
    huntzhan  
    OP
       2016-08-14 23:10:40 +08:00
    @hinkal 对不起, 我太 low 了, 只能做一些垃圾项目, 以后还要向菊苣学习一个
    shiina
        50
    shiina  
       2016-08-14 23:10:56 +08:00
    好像刚在 python-cn 见过你
    hinkal
        51
    hinkal  
       2016-08-14 23:13:23 +08:00
    @huntzhan 何必这么敏感,就是觉得这项目比较垃圾,没说我个人厉害,也没说你的水平不行啊
    huntzhan
        52
    huntzhan  
    OP
       2016-08-14 23:16:00 +08:00
    @hinkal Cool
    Xuanwo
        53
    Xuanwo  
       2016-08-14 23:18:10 +08:00
    道理我都懂,不过用 Github 当图床不太合适,除非这些图片完全用于技术讨论或者分享。
    huntzhan
        54
    huntzhan  
    OP
       2016-08-14 23:23:44 +08:00
    @Xuanwo reference request
    slixurd
        55
    slixurd  
       2016-08-14 23:41:49 +08:00
    就我一个人觉得这个项目没什么问题么
    滥不滥用全看个人而已
    如果只是把这个工具作为写 gitpages 时一个简易上传图片的工具,这就没什么问题
    不过也对,在 V 站只要站个队就好了。。。
    tianzhidao28
        56
    tianzhidao28  
       2016-08-15 01:08:55 +08:00
    不错
    hackpro
        57
    hackpro  
       2016-08-15 07:04:37 +08:00
    很好啊,能不能加个 feature 返回 url 直接复制到系统剪切板
    kitalphaj
        58
    kitalphaj  
       2016-08-15 08:37:50 +08:00
    顶楼主,总有人喜欢总有人讨厌,不要太在意
    pein
        59
    pein  
       2016-08-15 09:10:09 +08:00
    用这个办法上传的图片,如果访问的人很多(比如淘宝的量级),可能会造成 DDOS 一样的效果吧。如果量不大的话,应该是没问题的。
    aitaii
        60
    aitaii  
       2016-08-15 09:18:27 +08:00
    Github 不是图床...
    wizardoz
        61
    wizardoz  
       2016-08-15 09:24:33 +08:00
    不是说滥用 github 的行为会被举报吗?然后就被封号了。
    tairan2006
        62
    tairan2006  
       2016-08-15 10:07:16 +08:00
    用七牛不就行了,有免费流量啊。。 github 这个应该是属于滥用的
    huntzhan
        63
    huntzhan  
    OP
       2016-08-15 10:07:16 +08:00
    @hackpro 可以有
    huntzhan
        64
    huntzhan  
    OP
       2016-08-15 10:08:40 +08:00
    @tairan2006 好的, 我今天集成一下七牛的 API
    killerv
        65
    killerv  
       2016-08-15 10:12:44 +08:00
    项目不错,但是 github 不是个图床,做他应该做的事吧,图床有很多。
    yonka
        66
    yonka  
       2016-08-15 10:17:19 +08:00
    明显的恶意。
    难道一些些的对免费又干净的服务的感恩之心都那么困难吗?
    lzhr
        67
    lzhr  
       2016-08-15 13:02:09 +08:00
    12306 抢票插件拖垮 GitHub
    cnZary
        68
    cnZary  
       2016-08-15 13:57:08 +08:00
    GitHub 在国内本来就慢........给当做 cdn
    chocotan
        69
    chocotan  
       2016-08-15 14:20:56 +08:00
    我国什么人都有,滥用只是时间问题
    iyeatse
        70
    iyeatse  
       2016-08-15 15:45:13 +08:00
    讲道理微博图床你们一个个用得那么爽,改成 GitHub 摇身一变就成卫道士了?
    msg7086
        71
    msg7086  
       2016-08-16 01:41:53 +08:00   ❤️ 1
    拿微博当图床的怎么不跳出来说自己 abuse 呢。
    huntzhan
        72
    huntzhan  
    OP
       2016-08-17 10:44:55 +08:00
    @7sDream
    @cszhiyue
    @Xuanwo
    @we000
    @xmoiduts
    @Seita
    @wizardoz
    @chocotan

    > Hi Haoxun Zhan,
    >
    > Thanks for your question! We've reviewed your project and, in addition to uploading files, it appears to assist in generating rawgit URLs. Is that correct?
    >
    > If that's the case, your project doesn't appear to violate GitHub's Terms of Service, though you may want to check in with the owner of rawgit if you haven't already done so.
    >
    > Of course, any individual who decided to use your code would be responsible for making sure their usage and content didn't violate our Terms.
    >
    > Please let me know if you have any other questions.
    >
    > Best,
    > Elizabeth

    不好啦, 皇上...皇上他造反啦
    huntzhan
        73
    huntzhan  
    OP
       2016-08-17 23:29:59 +08:00
    @tairan2006 已经加入七牛的支持
    billion
        74
    billion  
       2016-08-18 13:17:08 +08:00
    借楼主的顺风车,推荐我的 MarkdownPicPicker ,

    不需要输入图片地址,自动读取剪贴板的图片,自动上传到图床。

    https://github.com/kingname/MarkdownPicPicker

    已经编译好可执行程序。
    enlau0912
        75
    enlau0912  
       2016-08-29 18:28:39 +08:00   ❤️ 3
    支持楼主 V2EX 搜寻图床 一堆人在那边讲微博图床,换成 github 立马跳脚,在这边骂街,结果人家站方还同意了,啪啪啪这脸响的
    saxon
        76
    saxon  
       2017-06-15 14:09:18 +08:00
    有木有 js 版本的呀
    huntzhan
        77
    huntzhan  
    OP
       2017-06-16 00:18:27 +08:00
    @saxon 没有
    GhostRider
        78
    GhostRider  
       2018-01-11 12:12:11 +08:00
    刚好我也有这个想法啊,,,就是用 github 做图床,以来仓库里面的文档可以看,同时用 github pages 的静态博客也可以很美观,,
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   4081 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 05:14 · PVG 13:14 · LAX 22:14 · JFK 01:14
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.