1.注册B2账号,点击进入B2 Cloud Storage,点击Buckets创建一个BUcket,设为public,并上传一个图片,记录下下图要用的域名
2.点击App keys,添加一个新的key,bucket就选你刚创建的那个,记录下你的密钥,之后要在ShareX中用
3.打开cf,cname一下上图要记的域名,小云朵点亮
4.加一条页面缓存规则.
5.创建一个workers,粘贴下列代码,记得b2domain和bucket的值改成自己的
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
'use strict'
;
const
b2Domain
=
'img.domain.com'
;
// configure this as per instructions above
const
b2Bucket
=
'bucket-name'
;
// configure this as per instructions above
const
b2UrlPath
=
`
/
file
/
$
{
b2Bucket
}
/
`
;
addEventListener
(
'fetch'
,
event
=&
gt
;
{
return
event
.
respondWith
(
fileReq
(
event
)
)
;
}
)
;
// define the file extensions we wish to add basic access control headers to
const
corsFileTypes
=
[
'png'
,
'jpg'
,
'gif'
,
'jpeg'
,
'webp'
]
;
// backblaze returns some additional headers that are useful for debugging, but unnecessary in production. We can remove these to save some size
const
removeHeaders
=
[
'x-bz-content-sha1'
,
'x-bz-file-id'
,
'x-bz-file-name'
,
'x-bz-info-src_last_modified_millis'
,
'X-Bz-Upload-Timestamp'
,
'Expires'
]
;
const
expiration
=
31536000
;
// override browser cache for images - 1 year
// define a function we can re-use to fix headers
const
fixHeaders
=
function
(
url
,
status
,
headers
)
{
let
newHdrs
=
new
Headers
(
headers
)
;
// add basic cors headers for images
if
(
corsFileTypes
.
includes
(
url
.
pathname
.
split
(
'.'
)
.
pop
(
)
)
)
{
newHdrs
.
set
(
'Access-Control-Allow-Origin'
,
'*'
)
;
}
// override browser cache for files when 200
if
(
status
===
200
)
{
newHdrs
.
set
(
'Cache-Control'
,
"public, max-age="
expiration
)
;
}
else
{
// only cache other things for 5 minutes
newHdrs
.
set
(
'Cache-Control'
,
'public, max-age=300'
)
;
}
// set ETag for efficient caching where possible
const
ETag
=
newHdrs
.
get
(
'x-bz-content-sha1'
)
||
newHdrs
.
get
(
'x-bz-info-src_last_modified_millis'
)
||
newHdrs
.
get
(
'x-bz-file-id'
)
;
if
(
ETag
)
{
newHdrs
.
set
(
'ETag'
,
ETag
)
;
}
// remove unnecessary headers
removeHeaders
.
forEach
(
header
=&
gt
;
{
newHdrs
.
delete
(
header
)
;
}
)
;
return
newHdrs
;
}
;
async
function
fileReq
(
event
)
{
const
cache
=
caches
.
default
;
// Cloudflare edge caching
const
url
=
new
URL
(
event
.
request
.
url
)
;
if
(
url
.
host
===
b2Domain
&
amp
;
&
amp
;
!
url
.
pathname
.
startsWith
(
b2UrlPath
)
)
{
url
.
pathname
=
b2UrlPath
url
.
pathname
;
}
let
response
=
await
cache
.
match
(
url
)
;
// try to find match for this request in the edge cache
if
(
response
)
{
// use cache found on Cloudflare edge. Set X-Worker-Cache header for helpful debug
let
newHdrs
=
fixHeaders
(
url
,
response
.
status
,
response
.
headers
)
;
newHdrs
.
set
(
'X-Worker-Cache'
,
"true"
)
;
return
new
Response
(
response
.
body
,
{
status
:
response
.
status
,
statusText
:
response
.
statusText
,
headers
:
newHdrs
}
)
;
}
// no cache, fetch image, apply Cloudflare lossless compression
response
=
await
fetch
(
url
,
{
cf
:
{
polish
:
"lossless"
}
}
)
;
let
newHdrs
=
fixHeaders
(
url
,
response
.
status
,
response
.
headers
)
;
if
(
response
.
status
===
200
)
{
response
=
new
Response
(
response
.
body
,
{
status
:
response
.
status
,
statusText
:
response
.
statusText
,
headers
:
newHdrs
}
)
;
}
else
{
response
=
new
Response
(
'File not found!'
,
{
status
:
404
}
)
}
event
.
waitUntil
(
cache
.
put
(
url
,
response
.
clone
(
)
)
)
;
return
response
;
}
|
6.workers里添加路由,使访问你的域名时,先走workers
访问一下你的图片文件
比如说一开始是https://f000.backblazeb2.com/file/backblaze1489498/wallhaven-md2x8m.jpg
现在用https://dlcu.cf/wallhaven-md2x8m.jpg就可以访问了
7.配置ShareX.
这个感觉没啥好说的,主页面–目标–上传目标设置–backblaze b2,填上就行了
这个的好处就是方便了上传,自己在电脑前,截一下图直接上传,或者复制一下直接上传
还有就是可以用自己的域名,再说的话就是数据自己也能找回.
原文:https://www.wangfuchao.com/1290/
免责声明:本站发布的内容(图片、视频和文字)以原创、来自本网站内容采集于网络互联网转载等其它媒体和分享为主,内容观点不代表本网站立场,如侵犯了原作者的版权,请告知一经查实,将立刻删除涉嫌侵权内容,联系我们QQ:712375056,同时欢迎投稿传递力量。
Copyright © 2009-2022 56dr.com. All Rights Reserved. 特网科技 特网云 版权所有 特网科技 粤ICP备16109289号
域名注册服务机构:阿里云计算有限公司(万网) 域名服务机构:烟台帝思普网络科技有限公司(DNSPod) CDN服务:阿里云计算有限公司 百度云 中国互联网举报中心 增值电信业务经营许可证B2
建议您使用Chrome、Firefox、Edge、IE10及以上版本和360等主流浏览器浏览本网站