-1

After uploading any other file after 1st upload i am getting HTTP - 417 error and File Not uploaded message as defined under my Spring UploadController.java file.

Spring Boot + Angular file upload getting error 400 bad request

After resolving my above query i am facing error 417 my above query includes all set of codes too including my Spring Controller file plus my Angular Component too.

In short at a moment able to upload only 1 document everytime i need to clear browsing history & cookies to upload successfully again. Wierd no idea of this.

8
  • 2
    it seems that in your next requests you don't set the necessary http headers. You should check: 1) what headers your server side service/controller needs to receive 2) what headers you send in your requests. You can also compare all headers in your working request with all the headers in your not working requests so you can understand the failing point Commented Jan 31, 2019 at 16:15
  • 1
    @AngeloImmediata - if there is any problems with headers then how come file gets uploaded once. Issue is arising while uploading files one after other without clearing cache Commented Feb 1, 2019 at 5:54
  • That’s why I told you to investigate on requests and compare the first one with the next ones. HTTP status code 417 is that the server doesn’t find a header on expect request so I’d investigate on requests Commented Feb 1, 2019 at 5:59
  • 1
    @AngeloImmediata okay i tried investigating the headers on both occasion only difference is under headers message - http Failure response URL: 417 Ok Commented Feb 1, 2019 at 6:30
  • 1
    @AngeloImmediata - stackoverflow.com/questions/54462480/… this query holds all set of codes both Spring + Angular Commented Feb 1, 2019 at 6:41

1 Answer 1

1

You have to reset your formData when you try to upload second file.

public formdata = new FormData(); 
    onSubmit() { 

    this.resetform();  //Order matters here
    let headers: any = new Headers(); 
    headers.append('Content-type', 'undefined'); 

    formData.append("selectFile", this.formData); 
    const req5 = new HttpRequest('POST', 'url as hosted on TOMCAT', formData, 
    reportProgress: true, 
    responseType: 'text' 
    }); 
    return this.httpClient.request(req5).subscribe(e => {( 
    console.log(e); 

    )} 
    } 

    resetform() { 
    this.formData = new FormData(); 
    }  

I hope it will solve your problem !!!

Sign up to request clarification or add additional context in comments.

1 Comment

i am accepting this as answer since it solved my query, cheers !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.