Current request is not a multipart request in spring boot backend #967

Open
opened 2018-01-22 01:30:12 +00:00 by alejuanito · 2 comments
alejuanito commented 2018-01-22 01:30:12 +00:00 (Migrated from github.com)

Hi, I try upload file to java backend but I have a error: Current request is not a multipart request.
When I use postman the file upload good but from angular frontend not working.

My code is:

`ngOnInit() {

this.uploader = new FileUploader({
url: "http://localhost:8084/ventas-api/api/companies/1/products/upload",
authToken :"eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZG1pbiIsImF1ZGllbmNlIjoid2ViIiwiY3JlYXRlZCI6MTUxNjU0NDAyNDE0NSwiZXhwIjoxNTE3MTQ4ODI0fQ._Oltuc4Jx_mfLXn89QbbT7zfBq5rkomUTCNsKPDGWTpUYtd9Y9HuQ0RmFnTa1_eGA9l_CPTTg1oJxdJ2i7buMg",
allowedMimeType: this.allowedMimeType,
maxFileSize: this.maxFileSize,
disableMultipart: true, // 'DisableMultipart' must be 'true' for formatDataFunction to be called.
formatDataFunctionIsAsync: true,
formatDataFunction: async (item) => {
  return new Promise( (resolve, reject) => {
    //let options = new RequestOptions();
    // let formData = new FormData();
    // formData.append("file", item.file, item._file.name);
    resolve({
      name: item._file.name,
      length: item._file.size,
      contentType: item._file.type,
      date: new Date()
    });
  });
}
});
this.hasBaseDropZoneOver = false;
this.hasAnotherDropZoneOver = false;
this.response = '';
this.uploader.response.subscribe( res => this.response = res );

//this.uploader.uploadAll();

this.uploader.onBuildItemForm = (item, form) => {
  console.log("onBuildItemForm");
};
this.uploader.onBeforeUploadItem = function(item) {

  console.log("onBeforeUploadItem");
}

}`

I change disableMultipart: true but the post not working.

Hi, I try upload file to java backend but I have a error: Current request is not a multipart request. When I use postman the file upload good but from angular frontend not working. My code is: `ngOnInit() { this.uploader = new FileUploader({ url: "http://localhost:8084/ventas-api/api/companies/1/products/upload", authToken :"eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZG1pbiIsImF1ZGllbmNlIjoid2ViIiwiY3JlYXRlZCI6MTUxNjU0NDAyNDE0NSwiZXhwIjoxNTE3MTQ4ODI0fQ._Oltuc4Jx_mfLXn89QbbT7zfBq5rkomUTCNsKPDGWTpUYtd9Y9HuQ0RmFnTa1_eGA9l_CPTTg1oJxdJ2i7buMg", allowedMimeType: this.allowedMimeType, maxFileSize: this.maxFileSize, disableMultipart: true, // 'DisableMultipart' must be 'true' for formatDataFunction to be called. formatDataFunctionIsAsync: true, formatDataFunction: async (item) => { return new Promise( (resolve, reject) => { //let options = new RequestOptions(); // let formData = new FormData(); // formData.append("file", item.file, item._file.name); resolve({ name: item._file.name, length: item._file.size, contentType: item._file.type, date: new Date() }); }); } }); this.hasBaseDropZoneOver = false; this.hasAnotherDropZoneOver = false; this.response = ''; this.uploader.response.subscribe( res => this.response = res ); //this.uploader.uploadAll(); this.uploader.onBuildItemForm = (item, form) => { console.log("onBuildItemForm"); }; this.uploader.onBeforeUploadItem = function(item) { console.log("onBeforeUploadItem"); } }` I change disableMultipart: true but the post not working.
o0bloody0o commented 2018-01-25 16:25:58 +00:00 (Migrated from github.com)

if you want to post a multipart request, maybe active multipart ? (disableMultipart: false, or nothing, it's false by default). If you want to add fields to your post request, use additionalParameter option.

can you show 2 post request (1 working, 1 not) ?

if you want to post a multipart request, maybe active multipart ? (disableMultipart: false, or nothing, it's false by default). If you want to add fields to your post request, use additionalParameter option. can you show 2 post request (1 working, 1 not) ?
molekilla commented 2018-03-08 13:55:06 +00:00 (Migrated from github.com)

With spring boot, it works as is.

@RequestMapping(method = RequestMethod.POST, path = "/{id}/documents") public DeferredResult<ResponseEntity<?>> uploadDocuments( @PathVariable String id, @RequestParam("file") MultipartFile[] files ) {

client
upload() { this.uploader.uploadAll(); } ngOnInit() { this.uploader = new FileUploader({ url:${config.API_URL}/v1/quote/${id}/documents}); }

With spring boot, it works as is. ` @RequestMapping(method = RequestMethod.POST, path = "/{id}/documents") public DeferredResult<ResponseEntity<?>> uploadDocuments( @PathVariable String id, @RequestParam("file") MultipartFile[] files ) { ` client ` upload() { this.uploader.uploadAll(); } ngOnInit() { this.uploader = new FileUploader({ url: `${config.API_URL}/v1/quote/${id}/documents` }); } `
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: dc/ng2-file-upload#967