DWQA QuestionsCategory: ProgramNo response from formdata + busboy upload file?
almondcookies asked 3 months ago

As the title, LZ is learning to upload files with formdata.
Front end JS file:

var fd= new FormData($('#musicup')[0]);//# Musicup is a form
    url: '/upload' ,
    method: 'POST',
    data: fd,
    async: false,
    cache: false,
    contentType: false,
    processData: false,
    success: function (returndata) {
    error: function (returndata) {

For Firefox used by the browser, no message header is generated initially when submitting, but after a long time (probably due to the timeout set in some place itself), a request header will be generated (no response header). Content type is multipart / form data; Boundary… These.
Then use chrome to immediately generate the header, content type or multipart / form data… The contents of formdata can be seen in the request payload and are all correct.
Keystone used at the back end is actually an encapsulated express + mongodb framework
A connect busboy middleware is used to receive files,
Backend JS:

    console.log("Uploading: " + filename);
   //Some processing
req.busboy.on('field',function(fieldname, val, fieldnametruncated, valtruncated){
    console.log(fieldname+", "+ inspect(val));
    console.log("finished uploading");

As a result, only the finish event is triggered, and file, data and field are not triggered
Which great God led the way… T t has been tangled for a long time..
*The data fields uploaded with $. Ajax () are normal objects, so I suspect it’s the problem of formdata + Ajax, but when looking at the header with chrome, it’s payload…
OTZ,I have also encountered this problem for a long time. I don’t know if you have solved it

1 Answers
xjl271314 answered 3 months ago

I have also encountered this problem for a long time. I don’t know if you have solved it

almondcookies replied 3 months ago

Are you using keystone framework

xjl271314 replied 3 months ago

No, my problem has been solved before. It’s a cross domain problem of uploading