Skip to content

Commit

Permalink
🐛 表单提交支持文件的文件名
Browse files Browse the repository at this point in the history
  • Loading branch information
di4urp committed Jul 14, 2019
1 parent ba7cd21 commit f6c98ae
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion upyun/form-upload.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import FormData from 'form-data'
import path from 'path'

export default function formUpload (remoteUrl, localFile, {authorization, policy}) {
return new Promise((resolve, reject) => {
Expand All @@ -8,8 +9,12 @@ export default function formUpload (remoteUrl, localFile, {authorization, policy
// NOTE when type of localFile is buffer/string,
// force set filename=file, FormData will treat it as a file
// real filename will be set by save-key in policy
const filename = (localFile.name || localFile.path) ?
path.basename(localFile.name || localFile.path) :
'file'

data.append('file', localFile, {
filename: 'file'
filename: filename
})
data.submit(remoteUrl, (err, res) => {
if (err) {
Expand Down

0 comments on commit f6c98ae

Please sign in to comment.