m4nuC / async-busboy

Promise based multipart form parser for KoaJS
MIT License
167 stars 57 forks source link

can't get files #5

Closed haozi23333 closed 8 years ago

haozi23333 commented 8 years ago
apiroute.post("/upload",async function (ctx,next) {
    asyncBusboy(ctx.req).then(function (formData) {
        console.log(formData);
    })
});
console  ->  { fields: { modName: '23333', mod: 'undefined' }, files: [] }

this files is empty use koa-router and async-busboy

whit demo

 var bd = new FormData();
                bd.append("modName","23333");
                bd.append("mod",sj.file);
                    $.ajax({
                        url: '/api/upload',
                        type:"post",
                        cache:false,
                        data:bd,
                        processData: false,
                        contentType:false,
                        success:function () {
                            console.log("OK");
                        }
                    });
            }
m4nuC commented 8 years ago

In your example what is sj.file are you sure it is a valid file ? Can you inspect the payload data on the request on post it here ?

mqliutie commented 4 years ago

@m4nuC I have met same problem... image In this way I can not get files but fields have value

{
  "------WebKitFormBoundaryeKsggfjo2wYJ61ny\r\nContent-Disposition: form-data; name": "\"orderIn\"; filename=\"a.json\"\r\nContent-Type: application/json\r\n\r\n{\n    \"type\": \"object\",\n    \"$id\": \"https://mqliutie.com/schemas/a.json\",\n    \"properties\": {\n        \"api\": {\n            \"type\": \"string\"\n        },\n        \"data\": {\n            \"type\": \"object\",\n            \"properties\": {\n                \"activityStartTime\": {\n                    \"type\": \"string\"\n                }\n            }\n        }\n    },\n    \"required\": [\n        \"api\"\n    ]\n}\r\n------WebKitFormBoundaryeKsggfjo2wYJ61ny\r\nContent-Disposition: form-data; name=\"userName\"\r\n\r\nuserName diy\r\n------WebKitFormBoundaryeKsggfjo2wYJ61ny--\r\n"
}

If upload in another way image I can get the files