- 資訊首頁(yè) > 互聯(lián)網(wǎng) > 主機資訊 >
- #實(shí)用教程#backblaze cloudflare ShareX 實(shí)現無(wú)成本圖床
1.注冊B2賬號,點(diǎn)擊進(jìn)入B2 Cloud Storage,點(diǎn)擊Buckets創(chuàng )建一個(gè)BUcket,設為public,并上傳一個(gè)圖片,記錄下下圖要用的域名
2.點(diǎn)擊App keys,添加一個(gè)新的key,bucket就選你剛創(chuàng )建的那個(gè),記錄下你的密鑰,之后要在ShareX中用
3.打開(kāi)cf,cname一下上圖要記的域名,小云朵點(diǎn)亮
4.加一條頁(yè)面緩存規則.
5.創(chuàng )建一個(gè)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里添加路由,使訪(fǎng)問(wèn)你的域名時(shí),先走workers
訪(fǎng)問(wèn)一下你的圖片文件
比如說(shuō)一開(kāi)始是https://f000.backblazeb2.com/file/backblaze1489498/wallhaven-md2x8m.jpg
現在用https://dlcu.cf/wallhaven-md2x8m.jpg就可以訪(fǎng)問(wèn)了
7.配置ShareX.
這個(gè)感覺(jué)沒(méi)啥好說(shuō)的,主頁(yè)面–目標–上傳目標設置–backblaze b2,填上就行了
這個(gè)的好處就是方便了上傳,自己在電腦前,截一下圖直接上傳,或者復制一下直接上傳
還有就是可以用自己的域名,再說(shuō)的話(huà)就是數據自己也能找回.
原文:https://www.wangfuchao.com/1290/
免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng )、來(lái)自本網(wǎng)站內容采集于網(wǎng)絡(luò )互聯(lián)網(wǎng)轉載等其它媒體和分享為主,內容觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如侵犯了原作者的版權,請告知一經(jīng)查實(shí),將立刻刪除涉嫌侵權內容,聯(lián)系我們QQ:712375056,同時(shí)歡迎投稿傳遞力量。
Copyright ? 2009-2022 56dr.com. All Rights Reserved. 特網(wǎng)科技 特網(wǎng)云 版權所有 特網(wǎng)科技 粵ICP備16109289號
域名注冊服務(wù)機構:阿里云計算有限公司(萬(wàn)網(wǎng)) 域名服務(wù)機構:煙臺帝思普網(wǎng)絡(luò )科技有限公司(DNSPod) CDN服務(wù):阿里云計算有限公司 百度云 中國互聯(lián)網(wǎng)舉報中心 增值電信業(yè)務(wù)經(jīng)營(yíng)許可證B2
建議您使用Chrome、Firefox、Edge、IE10及以上版本和360等主流瀏覽器瀏覽本網(wǎng)站