Hi,
Here is my code, which fires an Upload failed error, when I click on the Upload button without selecting any files. I know it is because of returning null value, but instead of this null I tried “return new ByteArrayOutputStream();” , still it shows Upload failed error.
I also tried to disable upload button using addChangeListener, but it disables the upload button only for first time.
How can I fix these issues, can anybody help me, Thanks in advance.!!!
private class ImageUploader implements Receiver, SucceededListener
{
private static final long serialVersionUID = -878399743277824104L;
public File file;
@Override
public OutputStream receiveUpload(String filename, String mimeType)
{
FileOutputStream fos = null; // Stream to write to
try
{
String tmpFolderLoc = getLocalFileLocation();
// Open the file for writing.
file = new File(tmpFolderLoc + File.separatorChar + filename);
fos = new FileOutputStream(file);
} catch (final java.io.FileNotFoundException e)
{
new Notification("Could not open file<br/>", e.getMessage(), Notification.Type.ERROR_MESSAGE).show(Page.getCurrent());
return new ByteArrayOutputStream();
}
return fos; // Return the output stream to write to
}
@Override
public void uploadSucceeded(SucceededEvent event)
{
attachCall.afterAttachementDone(file);
// attachUpload.setButtonCaption(null);
// refresh();
}
}