package app.controllers;
import net.coobird.thumbnailator.Thumbnails;
import net.coobird.thumbnailator.name.Rename;
import org.javalite.activeweb.AppController;
import org.javalite.activeweb.FormItem;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLDecoder;
import java.util.*;
/**
* @author Gianna Giavelli
*/
public class UploadController extends AppController
{
public void index() {}
@POST
public void save() throws IOException
{
List<FormItem> items = multipartFormItems();
List<String> messages = new ArrayList<String>();
for (FormItem item : items)
{
if (item.isFile())
{
messages.add ("Found file: " + item.getFileName() );
//lotsa hoops to find path is there easier way?
URL r = this.getClass().getResource("/");
String strFileName = item.getFileName();
// path decoded "/C:/Program Files/Tomcat 6.0/webapps/myapp/WEB-INF/classes/"
String decoded = URLDecoder.decode(r.getFile(), "UTF-8");
String strThumbnailPath = new String();
String strFullsizePath = new String();
if (decoded.startsWith("/"))
{
decoded = decoded.replaceFirst("/", "");
decoded = decoded.replaceFirst("WEB-INF/classes/", "");
strThumbnailPath = decoded;
strFullsizePath = decoded;
decoded = decoded.concat("images/upload/");
decoded = decoded.concat(strFileName);
strThumbnailPath = strThumbnailPath.concat("images/thumbnails/");
strFullsizePath = strFullsizePath.concat("images/fullscreen/");
}
System.out.println("decoded:" + decoded); //where to go hunt your thumbnails and uploads!
BufferedInputStream oInputStream = new BufferedInputStream (item.getInputStream());