• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Jj Roberts
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Himai Minh
  • Carey Brown
  • salvin francis

File Upload using SPRING REST API

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am trying to upload file using POSTMAN REST client. i have configured Content-Type=multipart/form-data;boundary=---------------------------sdjkahdj294919323195 and file=<file.txt>

This is my controller.



Added this in spring.xml


But when i send url http://localhost:8080/myapp/rest/uploadfile.json , i am getting HTTP Status 400 - The request sent by the client was syntactically incorrect ().

Can anyone help in finding the mistake.

Thanks in advance
Vinay
 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the issue is with the URL. Please check once as this bean cannot be identied with the given URL.

And one more thing the way you are handling the file stream would be problem for huge files.we need to take help of disk file to store it temporarly
please see below code if it is useful for you or not
boolean isMultipart = ServletFileUpload.isMultipartContent(request);


if (isMultipart) {

FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload servletFileUpload = new ServletFileUpload(factory);
servletFileUpload.setSizeMax(-1);

try {

List items = servletFileUpload.parseRequest(request);
Iterator iter = items.iterator();
while (iter.hasNext()) {
FileItem item = (FileItem) iter.next();
if (!item.isFormField()) {
String fileName = item.getName();
long fileSize = item.getSize();
String contentType = item.getContentType();
InputStream is = item.getInputStream();
 
Being a smart alec beats the alternative. This tiny ad knows what I'm talking about:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic