20 Ekim 2019 Pazar

SpringMVC CommonsMultipartFile Sınıfı

Giriş
Şu satırı dahil ederiz. MultipartFile arayüzünü gerçekleştirir.
import org.springframework.web.multipart.commons.CommonsMultipartFile;
Açıklaması şöyle.
Spring also makes it easy to handle file upload within a handler method, by automatically binding upload data to an array of CommonsMultipartFile objects. Spring uses Apache Commons FileUpload as the underlying multipart resolver.
Örnek
Şöyle yaparız.
@RequestMapping(value = "/uploadFiles", method = RequestMethod.POST)
public String handleFileUpload(@RequestParam CommonsMultipartFile[] fileUpload)
  throws Exception {

  for (CommonsMultipartFile aFile : fileUpload){
    // stores the uploaded file
    aFile.transferTo(new File(aFile.getOriginalFilename()));
  }
  return "Success";
}


Hiç yorum yok:

Yorum Gönder