Hi,
can some one provide me an example of how to upload a file to server using vaadin upload component.
the demo examples doesnt show how to upload the file .
–
Regards,
Niyas
Hi,
can some one provide me an example of how to upload a file to server using vaadin upload component.
the demo examples doesnt show how to upload the file .
–
Regards,
Niyas
Could you elaborate a little more on what info do you need? You’ve probably already checked out the
relevant Sampler section
, right?
Hi Risto,
thanks for the reply.
Basically i want to store the file the user uploads in the server .
How can we process the recieveUpload method to implement this .
Usually using java we read the content as byte array and create the file using the FileOutputStream.write[byte[]
ar]
method.
How can i develop the same using vaadin
–
Regards,
Niyas
Yes, you have a byteStream, write it anywhere you want.
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import com.vaadin.ui.Upload.Receiver;
public class UploadReceiver implements Receiver {
private static final long serialVersionUID = 2215337036540966711L;
OutputStream outputFile = null;
@Override
public OutputStream receiveUpload(String strFilename, String strMIMEType) {
File file=null;
try {
file = new File("H:/"+strFilename);
if(!file.exists()) {
file.createNewFile();
}
outputFile = new FileOutputStream(file);
} catch (IOException e) {
e.printStackTrace();
}
return outputFile;
}
protected void finalize() {
try {
super.finalize();
if(outputFile!=null) {
outputFile.close();
}
} catch (Throwable exception) {
exception.printStackTrace();
}
}
}
I dont completely follow this, we need to get the file contents or atleast the file descriptor so that we can upload it to where ever we want.
following this code of Pranay, we can only create an empty file which is of no use.
I dont get the purpose of upload component either, when it wont help at least putting the file in a common folder (like in java System.getProperty(“user.home”) or something like this) we may not read all the files properly with just bytestream can we?
in above code: file = new File(“H:/”+strFilename);
H:/ is drive in your LocalPc.
But when user wont have the same drive as you have or the file may not be saved into that file, then how we can give the path dynamically