File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Spring and the fly likes File Upload using SPRING REST API Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "File Upload using SPRING REST API" Watch "File Upload using SPRING REST API" New topic

File Upload using SPRING REST API

Vinay Dinakar

Joined: Dec 30, 2008
Posts: 17

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 Ds
bala nannaka
Ranch Hand

Joined: Apr 02, 2007
Posts: 49
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);

try {

List items = servletFileUpload.parseRequest(request);
Iterator iter = items.iterator();
while (iter.hasNext()) {
FileItem item = (FileItem);
if (!item.isFormField()) {
String fileName = item.getName();
long fileSize = item.getSize();
String contentType = item.getContentType();
InputStream is = item.getInputStream();
wood burning stoves
subject: File Upload using SPRING REST API
It's not a secret anymore!