• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

File Upload using SPRING REST API

 
Vinay Dinakar
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
 
bala nannaka
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();
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic