Skip to content

Commit 68397d1

Browse files
committed
fixed xhr when binnary
1 parent aeb7b86 commit 68397d1

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-core-image-upload",
3-
"version": "2.1.5",
3+
"version": "2.1.6",
44
"description": "a vue plgin for image upload and crop",
55
"main": "src/index.js",
66
"dependencies": {

site/client/components/doc/cn/CompressImage.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
@imageuploaded="imageUploded"
1010
:max-file-size="5242880"
1111
compress="50"
12+
:data="params"
1213
url="http://101.198.151.190/api/upload.php" >
1314
</vue-core-image-upload>
1415
</div>
@@ -25,14 +26,18 @@
2526

2627
<script>
2728
28-
import VueCoreImageUpload from 'vue-core-image-upload'
29+
import VueCoreImageUpload from '../../../../src/vue-core-image-upload.vue'
2930
export default {
3031
components: {
3132
VueCoreImageUpload,
3233
},
3334
data() {
3435
return {
3536
src: 'http://img1.vued.vanthink.cn/vued0a233185b6027244f9d43e653227439a.png',
37+
params: {
38+
auth: '123123',
39+
arr: [123,123123]
40+
}
3641
};
3742
},
3843

src/lib/xhr.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/**
22
* simple ajax handler
33
**/
4-
54
//ADD sendAsBinary compatibilty to older browsers
65
if (XMLHttpRequest.prototype.sendAsBinary === undefined) {
76
XMLHttpRequest.prototype.sendAsBinary = function(string) {
@@ -25,6 +24,7 @@ module.exports = function (method, url, headers, data, callback, err, isBinary)
2524
binary = method;
2625
method = 'GET';
2726
}
27+
console.log(data);
2828
method = method.toUpperCase();
2929
// Xhr.responseType 'json' is not supported in any of the vendors yet.
3030
r.onload = function () {
@@ -54,8 +54,19 @@ module.exports = function (method, url, headers, data, callback, err, isBinary)
5454
if (method === 'GET' || method === 'DELETE') {
5555
data = null;
5656
} else if (isBinary) {
57+
const keyData = data;
5758
const code = data.base64Code.replace('data:' + data.type + ';base64,', '');
58-
data = ['--' + boundary, 'Content-Disposition: form-data; name="' + data.filed + '"; filename="' + data.filename + '"', 'Content-Type: ' + data.type, '', window.atob(code), '--' + boundary + '--'].join('\r\n');
59+
data = ['--' + boundary, 'Content-Disposition: form-data; name="' + data.filed + '"; filename="' + data.filename + '"', 'Content-Type: ' + data.type, '', window.atob(code), ''].join('\r\n');
60+
const keyArr = Object.keys(keyData);
61+
if (keyArr.length > 4) {
62+
for (const k of keyArr) {
63+
if (['filed', 'filename', 'type', 'base64Code'].indexOf(k) == -1) {
64+
data += ['--' + boundary, 'Content-Disposition: form-data; name="' + k + '";', '', ''].join('\r\n');
65+
data += [typeof keyData[k] === 'object' ? JSON.stringify(keyData[k]) : keyData[k], ''].join('\r\n');
66+
}
67+
}
68+
}
69+
data += '--' + boundary + '--';
5970
}
6071
// Open the path, async
6172
r.open(method, url, true);

0 commit comments

Comments
 (0)