Skip to content

Commit f6c98ae

Browse files
committed
🐛 表单提交支持文件的文件名
1 parent ba7cd21 commit f6c98ae

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

upyun/form-upload.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import FormData from 'form-data'
2+
import path from 'path'
23

34
export default function formUpload (remoteUrl, localFile, {authorization, policy}) {
45
return new Promise((resolve, reject) => {
@@ -8,8 +9,12 @@ export default function formUpload (remoteUrl, localFile, {authorization, policy
89
// NOTE when type of localFile is buffer/string,
910
// force set filename=file, FormData will treat it as a file
1011
// real filename will be set by save-key in policy
12+
const filename = (localFile.name || localFile.path) ?
13+
path.basename(localFile.name || localFile.path) :
14+
'file'
15+
1116
data.append('file', localFile, {
12-
filename: 'file'
17+
filename: filename
1318
})
1419
data.submit(remoteUrl, (err, res) => {
1520
if (err) {

0 commit comments

Comments
 (0)