kaan
kaan

Reputation: 61

null value in file upload by using MultipartFile in spring 2.5

I am stucked to something. In spring 2.5 framework, I want to upload file by using MultipartFile. I have a class called Dosya including property which is MultipartFile multiDosya. My command object is dosya. Additonally, The file which will be uploaded is stored BLOB type in database, sql developer,. In jsp, I try to bind this propert like below:

<spring:bind path="dosya.multiDosya">
  <input class="file" type="file" name="yuklenecekDosya" id="yuklenecekDosya" />
</spring:bind>

In onSubmit,

 Dosya dosyaObjesi = (Dosya)command;
 MultipartFile yuklenecekDosya = dosyaObjesi.getMultiDosya();

The commandObject dosyaObjesi is taken without problem, however,

dosyaObjesi.getMultiDosya()

value is coming null although file that will be uploaded is selected in jsp.

After searching on the net, I found that this line below should be added to the initBinder.

 binder.registerCustomEditor(byte[].class, new ByteArrayMultipartFileEditor());

However, my class says that there is no such class ByteArrayMultipartFileEditor, but it is available in spring-2.5.jar. I import

import org.springframework.web.multipart.*;

can trace out the problem . could someone please help me out

Thanks in advance.

Upvotes: 1

Views: 1247

Answers (2)

kaan
kaan

Reputation: 61

I have solved the problem. Everything is ok, however, in the code below

<input class="file" type="file" name="yuklenecekDosya" id="yuklenecekDosya" />

the attribute name must be ${status.expression} . That is, exactly, name="${status.expression}" like that. If only the name property value is given like that, bind operation works correctly. Thanks, Regards,

Upvotes: 0

Praveen
Praveen

Reputation: 57

Have you specified form encryption type(enctype="multipart/form-data")?. That could be the reason sometimes.

Ex:

<form method="post"  name="formName" action="action.htm" commandName="object" enctype="multipart/form-data">

Upvotes: 1

Related Questions