aspose file tools*
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


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "File Upload using SPRING REST API" Watch "File Upload using SPRING REST API" New topic
Author

File Upload using SPRING REST API

Vinay Dinakar
Greenhorn

Joined: Dec 30, 2008
Posts: 17
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


Thanks,

~ 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);
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();
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: File Upload using SPRING REST API