Skip to content

Commit fb59681

Browse files
committed
✨ Feature: add mime-types for some uploaders
1 parent eb0f907 commit fb59681

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

src/plugins/uploader/github.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { IPicGo, IPluginConfig, IGithubConfig, IOldReqOptionsWithJSON } from '../../types'
22
import { IBuildInEvent } from '../../utils/enum'
33
import { ILocalesKey } from '../../i18n/zh-CN'
4+
import mime from 'mime-types'
45

56
const postOptions = (fileName: string, options: IGithubConfig, data: any): IOldReqOptionsWithJSON => {
67
const path = options.path || ''
@@ -10,7 +11,8 @@ const postOptions = (fileName: string, options: IGithubConfig, data: any): IOldR
1011
url: `https://api.github.com/repos/${repo}/contents/${encodeURI(path)}${encodeURI(fileName)}`,
1112
headers: {
1213
Authorization: `token ${token}`,
13-
'User-Agent': 'PicGo'
14+
'User-Agent': 'PicGo',
15+
'Content-Type': mime.lookup(fileName)
1416
},
1517
body: data,
1618
json: true

src/plugins/uploader/qiniu.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import qiniu from 'qiniu'
22
import { IPluginConfig, IQiniuConfig, IPicGo, IOldReqOptions } from '../../types'
33
import { IBuildInEvent } from '../../utils/enum'
44
import { ILocalesKey } from '../../i18n/zh-CN'
5+
import mime from 'mime-types'
56

67
function postOptions (options: IQiniuConfig, fileName: string, token: string, imgBase64: string): IOldReqOptions {
78
const area = selectArea(options.area || 'z0')
@@ -12,7 +13,7 @@ function postOptions (options: IQiniuConfig, fileName: string, token: string, im
1213
url: `http://upload${area}.qiniup.com/putb64/-1/key/${base64FileName}`,
1314
headers: {
1415
Authorization: `UpToken ${token}`,
15-
contentType: 'application/octet-stream'
16+
'Content-Type': mime.lookup(fileName) || 'application/octet-stream'
1617
},
1718
body: imgBase64
1819
}

src/plugins/uploader/upyun.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import MD5 from 'md5'
44
import { IBuildInEvent } from '../../utils/enum'
55
import { ILocalesKey } from '../../i18n/zh-CN'
66
import { safeParse } from '../../utils/common'
7+
import mime from 'mime-types'
78

89
// generate COS signature string
910
const generateSignature = (options: IUpyunConfig, fileName: string): string => {
@@ -26,7 +27,8 @@ const postOptions = (options: IUpyunConfig, fileName: string, signature: string,
2627
url: `https://v0.api.upyun.com/${bucket}/${encodeURI(path)}${encodeURI(fileName)}`,
2728
headers: {
2829
Authorization: signature,
29-
Date: new Date().toUTCString()
30+
Date: new Date().toUTCString(),
31+
'Content-Type': mime.lookup(fileName) || 'application/octet-stream'
3032
},
3133
body: image,
3234
resolveWithFullResponse: true

0 commit comments

Comments
 (0)