axios-upload
Advanced tools
Comparing version 1.0.5 to 1.0.7
29
index.js
@@ -5,23 +5,28 @@ 'use strict'; | ||
const FormData = require('form-data'); | ||
const fs = require('fs'); | ||
const contentType = 'content-type'; | ||
const isObject = (obj) => { | ||
return typeof obj === "object" && obj !== null; | ||
} | ||
return typeof obj === 'object' && obj !== null; | ||
}; | ||
const API = axios.create(); | ||
const instance = axios.create(); | ||
API.interceptors.request.use((config) => { | ||
instance.interceptors.request.use((config) => { | ||
const formData = config.data; | ||
const data = config.data; | ||
if (isObject(formData)) { | ||
if (isObject(data)) { | ||
config.maxContentLength || (config.maxContentLength = 1024 * 1024 * 100); | ||
config.transformRequest = [(data, headers) => { | ||
let form = new FormData(); | ||
for(let key in formData) { | ||
form.append(key, formData[key]); | ||
for (let key in data) { | ||
if (data.hasOwnProperty(key)) { | ||
form.append(key, data[key]); | ||
} | ||
} | ||
headers[contentType] = form.getHeaders()[contentType]; | ||
delete headers.post['Content-Type']; | ||
delete headers.put['Content-Type']; | ||
delete headers.patch['Content-Type']; | ||
Object.assign(headers, form.getHeaders()); | ||
return form; | ||
@@ -36,2 +41,2 @@ }]; | ||
module.exports = API; | ||
module.exports = instance; |
{ | ||
"name": "axios-upload", | ||
"version": "1.0.5", | ||
"version": "1.0.7", | ||
"description": "axios upload formdata", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "./node_modules/.bin/mocha" | ||
}, | ||
@@ -15,7 +15,6 @@ "repository": { | ||
"axios", | ||
"upload", | ||
"formdata" | ||
], | ||
"author": "jiayufeng", | ||
"license": "ISC", | ||
"license": "MIT", | ||
"bugs": { | ||
@@ -28,3 +27,8 @@ "url": "https://github.com/JYFiaueng/axios-upload/issues" | ||
"form-data": "^2.3.2" | ||
}, | ||
"devDependencies": { | ||
"@zhike/koa2-upload": "^1.0.0", | ||
"koa": "^2.5.1", | ||
"mocha": "^5.2.0" | ||
} | ||
} |
@@ -22,2 +22,3 @@ ## axios-upload | ||
// 这里直接将 stream 传入即可 | ||
// 文件默认上传最大为100M,若需修改,使用maxContentLength参数,单位byte | ||
const data = { | ||
@@ -24,0 +25,0 @@ name: 'test', |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
4333
6
0
53
0
36
3