Home » Eclipse Projects » Remote Application Platform (RAP) » Upload a file
Upload a file [message #64308] |
Tue, 04 December 2007 09:27  |
Eclipse User |
|
|
|
Hi,
it seems that it's no possible to browse a file from client filesystem
using something like FileDialog. My need is to browse a file and upload
it on a server. My idea is to use a browser widget in which i load a
jsp/servlet that manages uploading. Are there others ideas to make this job?
Thanks
Christian
|
|
| | | | | | |
Re: Upload a file [message #65093 is a reply to message #65068] |
Mon, 10 December 2007 03:38   |
Eclipse User |
|
|
|
I impleted my File upload/download system with rap internal Browser +
servlet.
upload dialog:
public class FileUploadDialog extends TitleAreaDialog {
private Browser browser;
public FileUploadDialog(Shell parentShell) {
super(parentShell);
}
/**
* Create contents of the dialog
* @param parent
*/
@Override
protected Control createDialogArea(Composite parent) {
Composite area = (Composite) super.createDialogArea(parent);
Composite container = new Composite(area, SWT.NONE);
container.setLayout(new FillLayout());
container.setLayoutData(new GridData(GridData.FILL_BOTH));
browser = new Browser(container, SWT.NONE);
String url =
"http://"+RWT.getRequest().getServerName()+":"+RWT.getRequest().getServerPort()+ "/web/fileupload.jsp";
String html = "<?xml version=\"1.0\" encoding=\"utf-8\"
?><html><head><title>upload file</title></head><body>"+
"<form action=\""+url+"\" enctype=\"MULTIPART/FORM-DATA\"
method=\"post\"><br />File Name:</br><input type=\"file\""+
" name=\"filename\"/><br><input type=\"submit\"
value=\"upload\"/></form></body></html> ";
browser.setText(html);
setMessage("select a local file");
return area;
}
/**
* Return the initial size of the dialog
*/
@Override
protected Point getInitialSize() {
return new Point(382, 280);
}
protected void configureShell(Shell newShell) {
super.configureShell(newShell);
newShell.setText("upload file");
}
}
file upload sevlet:
public class FileUploadServlet extends HttpServlet {
private static final long serialVersionUID = -7245361228773015964L;
private String uploadPath = "/upload/"; // server file repository
private String tempPath = "/upload/tmp/"; //temp file folder
public void doPost(HttpServletRequest request, HttpServletResponse
response)
throws IOException, ServletException {
try {
DiskFileUpload fu = new DiskFileUpload();
// max file size
fu.setSizeMax(-1);
// buffer size
fu.setSizeThreshold(4096);
// temp path
fu.setRepositoryPath(tempPath);
// get all uploa file
List fileItems = fu.parseRequest(request);
Iterator i = fileItems.iterator();
while (i.hasNext()) {
FileItem fi = (FileItem) i.next();
// get the upload file name
String fileName = fi.getName();
String sep = System.getProperty("file.separator");
int index = fileName.lastIndexOf(sep);
if(index >-1){
fileName = fileName.substring(fileName.lastIndexOf(sep));
}
fi.write(new File(uploadPath + fileName));
response.getWriter().println(fileName+"upload success");
}
} catch (Exception e) {
//do something?
e.printStackTrace();
}
}
public void init() throws ServletException {
if (!new File(uploadPath).isDirectory())
new File(uploadPath).mkdirs();
if (!new File(tempPath).isDirectory())
new File(tempPath).mkdirs();
}
}
registe servlet:
public class HttpServiceTracker extends ServiceTracker {
public HttpServiceTracker(BundleContext context) {
super(context, HttpService.class.getName(), null);
}
public Object addingService(ServiceReference reference) {
final HttpService httpService = (HttpService) context
.getService(reference);
try {
//regist file upload servlet
HttpContext commonContext = new
BundleEntryHttpContext(context
.getBundle(), fileFolder);
httpService.registerResources(fileContext, "/",
commonContext);
Servlet adaptedJspServlet = new ContextPathServletAdaptor(
new FileUploadServlet(),
fileContext);
httpService.registerServlet(fileContext +
"/fileupload.file",
adaptedJspServlet, null, commonContext);
} catch (Exception e) {
e.printStackTrace();
}
return httpService;
}
public void removedService(ServiceReference reference, Object
service)
{
final HttpService httpService = (HttpService) service;
httpService.unregister(fileContext);
httpService.unregister(fileContext + "/fileupload.jsp");
super.removedService(reference, service);
}
}
start servlet:
add these code to the bundle start up method.
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
httpServiceTracker = new HttpServiceTracker(context);
httpServiceTracker.open();
System.out.println("IM resource servlet started...");
}
|
|
|
Re: Upload a file [message #65206 is a reply to message #65093] |
Mon, 10 December 2007 22:21   |
Eclipse User |
|
|
|
Originally posted by: john_zhu.i-len.com
Hi everybody,
I've got several questions here.
1. Anyone here knows how to implement support of resume upload?
2. How to show a progress bar for the upload process?
Thank you & best regards,
John
On Mon, 10 Dec 2007 08:38:26 +0000, lizzz wrote:
> I impleted my File upload/download system with rap internal Browser +
> servlet.
> upload dialog:
>
> public class FileUploadDialog extends TitleAreaDialog {
> private Browser browser;
>
> public FileUploadDialog(Shell parentShell) {
> super(parentShell);
> }
>
> /**
> * Create contents of the dialog
> * @param parent
> */
> @Override
> protected Control createDialogArea(Composite parent) {
> Composite area = (Composite) super.createDialogArea(parent);
> Composite container = new Composite(area, SWT.NONE);
> container.setLayout(new FillLayout());
> container.setLayoutData(new GridData(GridData.FILL_BOTH));
>
> browser = new Browser(container, SWT.NONE);
> String url =
> "http://"+RWT.getRequest().getServerName()+":"+RWT.getRequest().getServerPort()+ "/web/fileupload.jsp";
> String html = "<?xml version=\"1.0\" encoding=\"utf-8\"
> ?><html><head><title>upload file</title></head><body>"+
> "<form action=\""+url+"\" enctype=\"MULTIPART/FORM-DATA\"
> method=\"post\"><br />File Name:</br><input type=\"file\""+
> " name=\"filename\"/><br><input type=\"submit\"
> value=\"upload\"/></form></body></html> ";
> browser.setText(html);
> setMessage("select a local file");
> return area;
> }
>
> /**
> * Return the initial size of the dialog
> */
> @Override
> protected Point getInitialSize() {
> return new Point(382, 280);
> }
>
> protected void configureShell(Shell newShell) {
> super.configureShell(newShell);
> newShell.setText("upload file");
> }
>
> }
>
>
> file upload sevlet:
>
> public class FileUploadServlet extends HttpServlet {
> private static final long serialVersionUID = -7245361228773015964L;
> private String uploadPath = "/upload/"; // server file repository
> private String tempPath = "/upload/tmp/"; //temp file folder
>
> public void doPost(HttpServletRequest request, HttpServletResponse
> response)
> throws IOException, ServletException {
> try {
> DiskFileUpload fu = new DiskFileUpload();
> // max file size
> fu.setSizeMax(-1);
> // buffer size
> fu.setSizeThreshold(4096);
> // temp path
> fu.setRepositoryPath(tempPath);
>
> // get all uploa file
> List fileItems = fu.parseRequest(request);
> Iterator i = fileItems.iterator();
> while (i.hasNext()) {
> FileItem fi = (FileItem) i.next();
> // get the upload file name
> String fileName = fi.getName();
> String sep = System.getProperty("file.separator");
> int index = fileName.lastIndexOf(sep);
> if(index >-1){
> fileName = fileName.substring(fileName.lastIndexOf(sep));
> }
> fi.write(new File(uploadPath + fileName));
> response.getWriter().println(fileName+"upload success");
> }
> } catch (Exception e) {
> //do something?
> e.printStackTrace();
> }
> }
> public void init() throws ServletException {
> if (!new File(uploadPath).isDirectory())
> new File(uploadPath).mkdirs();
> if (!new File(tempPath).isDirectory())
> new File(tempPath).mkdirs();
> }
> }
>
> registe servlet:
>
>
> public class HttpServiceTracker extends ServiceTracker {
>
> public HttpServiceTracker(BundleContext context) {
> super(context, HttpService.class.getName(), null);
> }
>
> public Object addingService(ServiceReference reference) {
> final HttpService httpService = (HttpService) context
> .getService(reference);
> try {
> //regist file upload servlet
> HttpContext commonContext = new
> BundleEntryHttpContext(context
> .getBundle(), fileFolder);
> httpService.registerResources(fileContext, "/",
> commonContext);
>
> Servlet adaptedJspServlet = new ContextPathServletAdaptor(
> new FileUploadServlet(),
> fileContext);
> httpService.registerServlet(fileContext +
> "/fileupload.file",
> adaptedJspServlet, null, commonContext);
>
> } catch (Exception e) {
> e.printStackTrace();
> }
> return httpService;
> }
>
> public void removedService(ServiceReference reference, Object
> service)
> {
> final HttpService httpService = (HttpService) service;
> httpService.unregister(fileContext);
> httpService.unregister(fileContext + "/fileupload.jsp");
> super.removedService(reference, service);
> }
> }
>
> start servlet:
>
> add these code to the bundle start up method.
> public void start(BundleContext context) throws Exception {
> super.start(context);
> plugin = this;
> httpServiceTracker = new HttpServiceTracker(context);
> httpServiceTracker.open();
> System.out.println("IM resource servlet started...");
> }
|
|
| |
Re: Upload a file [message #65857 is a reply to message #65206] |
Wed, 12 December 2007 05:39   |
Eclipse User |
|
|
|
Originally posted by: just4lists.nospammail.net
The commited upload widget (to the sandbox) already includes a parameter to
show or not a progress bar.
Regards,
Joel Oliveira
"John Zhu" <john_zhu@i-len.com> escreveu na mensagem
news:fjkvog$veu$1@build.eclipse.org...
> Hi everybody,
> I've got several questions here.
> 1. Anyone here knows how to implement support of resume upload?
> 2. How to show a progress bar for the upload process?
>
> Thank you & best regards,
> John
>
> On Mon, 10 Dec 2007 08:38:26 +0000, lizzz wrote:
>
>> I impleted my File upload/download system with rap internal Browser +
>> servlet.
>> upload dialog:
>>
>> public class FileUploadDialog extends TitleAreaDialog {
>> private Browser browser;
>>
>> public FileUploadDialog(Shell parentShell) {
>> super(parentShell);
>> }
>>
>> /**
>> * Create contents of the dialog
>> * @param parent
>> */
>> @Override
>> protected Control createDialogArea(Composite parent) {
>> Composite area = (Composite) super.createDialogArea(parent);
>> Composite container = new Composite(area, SWT.NONE);
>> container.setLayout(new FillLayout());
>> container.setLayoutData(new GridData(GridData.FILL_BOTH));
>>
>> browser = new Browser(container, SWT.NONE);
>> String url =
>> "http://"+RWT.getRequest().getServerName()+":"+RWT.getRequest().getServerPort()+ "/web/fileupload.jsp";
>> String html = "<?xml version=\"1.0\" encoding=\"utf-8\"
>> ?><html><head><title>upload file</title></head><body>"+
>> "<form action=\""+url+"\" enctype=\"MULTIPART/FORM-DATA\"
>> method=\"post\"><br />File Name:</br><input type=\"file\""+
>> " name=\"filename\"/><br><input type=\"submit\"
>> value=\"upload\"/></form></body></html> ";
>> browser.setText(html);
>> setMessage("select a local file");
>> return area;
>> }
>>
>> /**
>> * Return the initial size of the dialog
>> */
>> @Override
>> protected Point getInitialSize() {
>> return new Point(382, 280);
>> }
>>
>> protected void configureShell(Shell newShell) {
>> super.configureShell(newShell);
>> newShell.setText("upload file");
>> }
>>
>> }
>>
>>
>> file upload sevlet:
>>
>> public class FileUploadServlet extends HttpServlet {
>> private static final long serialVersionUID = -7245361228773015964L;
>> private String uploadPath = "/upload/"; // server file repository
>> private String tempPath = "/upload/tmp/"; //temp file folder
>>
>> public void doPost(HttpServletRequest request, HttpServletResponse
>> response)
>> throws IOException, ServletException {
>> try {
>> DiskFileUpload fu = new DiskFileUpload();
>> // max file size
>> fu.setSizeMax(-1);
>> // buffer size
>> fu.setSizeThreshold(4096);
>> // temp path
>> fu.setRepositoryPath(tempPath);
>>
>> // get all uploa file
>> List fileItems = fu.parseRequest(request);
>> Iterator i = fileItems.iterator();
>> while (i.hasNext()) {
>> FileItem fi = (FileItem) i.next();
>> // get the upload file name
>> String fileName = fi.getName();
>> String sep = System.getProperty("file.separator");
>> int index = fileName.lastIndexOf(sep);
>> if(index >-1){
>> fileName = fileName.substring(fileName.lastIndexOf(sep));
>> }
>> fi.write(new File(uploadPath + fileName));
>> response.getWriter().println(fileName+"upload success");
>> }
>> } catch (Exception e) {
>> //do something?
>> e.printStackTrace();
>> }
>> }
>> public void init() throws ServletException {
>> if (!new File(uploadPath).isDirectory())
>> new File(uploadPath).mkdirs();
>> if (!new File(tempPath).isDirectory())
>> new File(tempPath).mkdirs();
>> }
>> }
>>
>> registe servlet:
>>
>>
>> public class HttpServiceTracker extends ServiceTracker {
>>
>> public HttpServiceTracker(BundleContext context) {
>> super(context, HttpService.class.getName(), null);
>> }
>>
>> public Object addingService(ServiceReference reference) {
>> final HttpService httpService = (HttpService) context
>> .getService(reference);
>> try {
>> //regist file upload servlet
>> HttpContext commonContext = new
>> BundleEntryHttpContext(context
>> .getBundle(), fileFolder);
>> httpService.registerResources(fileContext, "/",
>> commonContext);
>>
>> Servlet adaptedJspServlet = new
>> ContextPathServletAdaptor(
>> new FileUploadServlet(),
>> fileContext);
>> httpService.registerServlet(fileContext +
>> "/fileupload.file",
>> adaptedJspServlet, null, commonContext);
>>
>> } catch (Exception e) {
>> e.printStackTrace();
>> }
>> return httpService;
>> }
>>
>> public void removedService(ServiceReference reference, Object
>> service)
>> {
>> final HttpService httpService = (HttpService) service;
>> httpService.unregister(fileContext);
>> httpService.unregister(fileContext + "/fileupload.jsp");
>> super.removedService(reference, service);
>> }
>> }
>>
>> start servlet:
>>
>> add these code to the bundle start up method.
>> public void start(BundleContext context) throws Exception {
>> super.start(context);
>> plugin = this;
>> httpServiceTracker = new HttpServiceTracker(context);
>> httpServiceTracker.open();
>> System.out.println("IM resource servlet started...");
>> }
|
|
| | | |
Re: Upload a file [message #66132 is a reply to message #66111] |
Thu, 13 December 2007 08:22   |
Eclipse User |
|
|
|
Originally posted by: rherrmann.innoopract.com
Tiago,
the code I use (see attachment in my previous post) does the same as
your snippet, but doesn't work.
First of all isFinished() never returns true. But even if, according to
the JavaDoc, the getLastFileUploaded() method returns the client path
name. Besides it seems to never get assigned (Ctrl+Shift+G on
lastFileUploaded field in Upload.java)
Cheers,
Rüdiger
Tiago wrote:
> You can use the following snipet to get the uploaded file name:
>
> Upload upload = new Upload(parent, SWT.NONE, null, true);
> upload.addUploadListener(new UploadAdapter() {
> public void uploadFinished(final UploadEvent uploadEvent) {
> if (uploadEvent.isFinished()) {
> String uploadedFileName = upload.getLastFileUploaded();
> }
> }
> });
>
> Hope it helps.
>
> Tiago
>
> "Christian" <zerostress@libero.it> wrote in message
> news:fjou7g$1on$1@build.eclipse.org...
>> Hi,
>>
>> i confirm the same problem.
>>
>> Christian
>>
>>
>> Rüdiger Herrmann ha scritto:
>>> Hi,
>>>
>>> I am at it... but can't find a way to obtain the uploaded data.
>>> From looking at the code, I seems to be written to a temp directory, but
>>> within the UploadListener I don't see a way to at least obtain the file
>>> name. Am I missing something?
>>> Attached is the code I wrote so far. It can be run as a new tab inside
>>> the ControlsDemo, just past the code and add
>>> new UploadTab( topFolder )
>>> to ControlsDemo#createContent(Composite)
>>> Of course you need to update the plug-in dependencies to include
>>> org...upload;)
>>>
>>>
>>> Cheers,
>>> Rüdiger
>>>
>>> Joel Oliveira wrote:
>>>> Waiting for validation from the core RAP Team. _:)
>>>>
>>>> "Setya" <jsetya@gmail.com> escreveu na mensagem
>>>> news:d908a33130c626aa4f832cc470088ee7$1@www.eclipse.org...
>>>>> Hi Joel,
>>>>>
>>>>> Thank you very much for your contribution on FileUpload widget. We
>>>>> too need this widget badly. When can we expect this widget be
>>>>> released officially (not through CVS) ?
>>>>>
>>>>> Regards,
>>>>>
>>>>> Setya
>>>>>
>
>
|
|
|
Re: Upload a file [message #66219 is a reply to message #65857] |
Thu, 13 December 2007 21:18   |
Eclipse User |
|
|
|
Originally posted by: john_zhu.i-len.com
Hi, Joel Oliveira:
I got it, but this widget provide only a File field for each form, I want
to send more information (such as file properties, keyword) and add multi
files dynamically, so I think I need to customize a widget. Thank you for
your answer.
John
On Wed, 12 Dec 2007 10:39:13 +0000, Joel Oliveira wrote:
> The commited upload widget (to the sandbox) already includes a parameter to
> show or not a progress bar.
>
> Regards,
>
> Joel Oliveira
>
> "John Zhu" <john_zhu@i-len.com> escreveu na mensagem
> news:fjkvog$veu$1@build.eclipse.org...
>> Hi everybody,
>> I've got several questions here.
>> 1. Anyone here knows how to implement support of resume upload?
>> 2. How to show a progress bar for the upload process?
>>
>> Thank you & best regards,
>> John
>>
>> On Mon, 10 Dec 2007 08:38:26 +0000, lizzz wrote:
>>
>>> I impleted my File upload/download system with rap internal Browser +
>>> servlet.
>>> upload dialog:
>>>
>>> public class FileUploadDialog extends TitleAreaDialog {
>>> private Browser browser;
>>>
>>> public FileUploadDialog(Shell parentShell) {
>>> super(parentShell);
>>> }
>>>
>>> /**
>>> * Create contents of the dialog
>>> * @param parent
>>> */
>>> @Override
>>> protected Control createDialogArea(Composite parent) {
>>> Composite area = (Composite) super.createDialogArea(parent);
>>> Composite container = new Composite(area, SWT.NONE);
>>> container.setLayout(new FillLayout());
>>> container.setLayoutData(new GridData(GridData.FILL_BOTH));
>>>
>>> browser = new Browser(container, SWT.NONE);
>>> String url =
>>> "http://"+RWT.getRequest().getServerName()+":"+RWT.getRequest().getServerPort()+ "/web/fileupload.jsp";
>>> String html = "<?xml version=\"1.0\" encoding=\"utf-8\"
>>> ?><html><head><title>upload file</title></head><body>"+
>>> "<form action=\""+url+"\" enctype=\"MULTIPART/FORM-DATA\"
>>> method=\"post\"><br />File Name:</br><input type=\"file\""+
>>> " name=\"filename\"/><br><input type=\"submit\"
>>> value=\"upload\"/></form></body></html> ";
>>> browser.setText(html);
>>> setMessage("select a local file");
>>> return area;
>>> }
>>>
>>> /**
>>> * Return the initial size of the dialog
>>> */
>>> @Override
>>> protected Point getInitialSize() {
>>> return new Point(382, 280);
>>> }
>>>
>>> protected void configureShell(Shell newShell) {
>>> super.configureShell(newShell);
>>> newShell.setText("upload file");
>>> }
>>>
>>> }
>>>
>>>
>>> file upload sevlet:
>>>
>>> public class FileUploadServlet extends HttpServlet {
>>> private static final long serialVersionUID = -7245361228773015964L;
>>> private String uploadPath = "/upload/"; // server file repository
>>> private String tempPath = "/upload/tmp/"; //temp file folder
>>>
>>> public void doPost(HttpServletRequest request, HttpServletResponse
>>> response)
>>> throws IOException, ServletException {
>>> try {
>>> DiskFileUpload fu = new DiskFileUpload();
>>> // max file size
>>> fu.setSizeMax(-1);
>>> // buffer size
>>> fu.setSizeThreshold(4096);
>>> // temp path
>>> fu.setRepositoryPath(tempPath);
>>>
>>> // get all uploa file
>>> List fileItems = fu.parseRequest(request);
>>> Iterator i = fileItems.iterator();
>>> while (i.hasNext()) {
>>> FileItem fi = (FileItem) i.next();
>>> // get the upload file name
>>> String fileName = fi.getName();
>>> String sep = System.getProperty("file.separator");
>>> int index = fileName.lastIndexOf(sep);
>>> if(index >-1){
>>> fileName = fileName.substring(fileName.lastIndexOf(sep));
>>> }
>>> fi.write(new File(uploadPath + fileName));
>>> response.getWriter().println(fileName+"upload success");
>>> }
>>> } catch (Exception e) {
>>> //do something?
>>> e.printStackTrace();
>>> }
>>> }
>>> public void init() throws ServletException {
>>> if (!new File(uploadPath).isDirectory())
>>> new File(uploadPath).mkdirs();
>>> if (!new File(tempPath).isDirectory())
>>> new File(tempPath).mkdirs();
>>> }
>>> }
>>>
>>> registe servlet:
>>>
>>>
>>> public class HttpServiceTracker extends ServiceTracker {
>>>
>>> public HttpServiceTracker(BundleContext context) {
>>> super(context, HttpService.class.getName(), null);
>>> }
>>>
>>> public Object addingService(ServiceReference reference) {
>>> final HttpService httpService = (HttpService) context
>>> .getService(reference);
>>> try {
>>> //regist file upload servlet
>>> HttpContext commonContext = new
>>> BundleEntryHttpContext(context
>>> .getBundle(), fileFolder);
>>> httpService.registerResources(fileContext, "/",
>>> commonContext);
>>>
>>> Servlet adaptedJspServlet = new
>>> ContextPathServletAdaptor(
>>> new FileUploadServlet(),
>>> fileContext);
>>> httpService.registerServlet(fileContext +
>>> "/fileupload.file",
>>> adaptedJspServlet, null, commonContext);
>>>
>>> } catch (Exception e) {
>>> e.printStackTrace();
>>> }
>>> return httpService;
>>> }
>>>
>>> public void removedService(ServiceReference reference, Object
>>> service)
>>> {
>>> final HttpService httpService = (HttpService) service;
>>> httpService.unregister(fileContext);
>>> httpService.unregister(fileContext + "/fileupload.jsp");
>>> super.removedService(reference, service);
>>> }
>>> }
>>>
>>> start servlet:
>>>
>>> add these code to the bundle start up method.
>>> public void start(BundleContext context) throws Exception {
>>> super.start(context);
>>> plugin = this;
>>> httpServiceTracker = new HttpServiceTracker(context);
>>> httpServiceTracker.open();
>>> System.out.println("IM resource servlet started...");
>>> }
|
|
| |
Re: Upload a file [message #66373 is a reply to message #66219] |
Fri, 14 December 2007 05:12   |
Eclipse User |
|
|
|
Originally posted by: just4lists.nospammail.net
Hi Jonh,
If possible, I would suggest something like a 2 steps approach:
- First let the user upload all the files;
- Second allow the user to tag the files with all the extra info
(properties, keywords, ...).
But if needed, you can extend this widget into a custom one.
Regards,
Joel Oliveira
"John Zhu" <john_zhu@i-len.com> escreveu na mensagem
news:fjsp62$50t$2@build.eclipse.org...
> Hi, Joel Oliveira:
>
> I got it, but this widget provide only a File field for each form, I want
> to send more information (such as file properties, keyword) and add multi
> files dynamically, so I think I need to customize a widget. Thank you for
> your answer.
>
> John
>
> On Wed, 12 Dec 2007 10:39:13 +0000, Joel Oliveira wrote:
>
>> The commited upload widget (to the sandbox) already includes a parameter
>> to
>> show or not a progress bar.
>>
>> Regards,
>>
>> Joel Oliveira
>>
>> "John Zhu" <john_zhu@i-len.com> escreveu na mensagem
>> news:fjkvog$veu$1@build.eclipse.org...
>>> Hi everybody,
>>> I've got several questions here.
>>> 1. Anyone here knows how to implement support of resume upload?
>>> 2. How to show a progress bar for the upload process?
>>>
>>> Thank you & best regards,
>>> John
>>>
>>> On Mon, 10 Dec 2007 08:38:26 +0000, lizzz wrote:
>>>
>>>> I impleted my File upload/download system with rap internal Browser +
>>>> servlet.
>>>> upload dialog:
>>>>
>>>> public class FileUploadDialog extends TitleAreaDialog {
>>>> private Browser browser;
>>>>
>>>> public FileUploadDialog(Shell parentShell) {
>>>> super(parentShell);
>>>> }
>>>>
>>>> /**
>>>> * Create contents of the dialog
>>>> * @param parent
>>>> */
>>>> @Override
>>>> protected Control createDialogArea(Composite parent) {
>>>> Composite area = (Composite) super.createDialogArea(parent);
>>>> Composite container = new Composite(area, SWT.NONE);
>>>> container.setLayout(new FillLayout());
>>>> container.setLayoutData(new GridData(GridData.FILL_BOTH));
>>>>
>>>> browser = new Browser(container, SWT.NONE);
>>>> String url =
>>>> "http://"+RWT.getRequest().getServerName()+":"+RWT.getRequest().getServerPort()+ "/web/fileupload.jsp";
>>>> String html = "<?xml version=\"1.0\" encoding=\"utf-8\"
>>>> ?><html><head><title>upload file</title></head><body>"+
>>>> "<form action=\""+url+"\" enctype=\"MULTIPART/FORM-DATA\"
>>>> method=\"post\"><br />File Name:</br><input type=\"file\""+
>>>> " name=\"filename\"/><br><input type=\"submit\"
>>>> value=\"upload\"/></form></body></html> ";
>>>> browser.setText(html);
>>>> setMessage("select a local file");
>>>> return area;
>>>> }
>>>>
>>>> /**
>>>> * Return the initial size of the dialog
>>>> */
>>>> @Override
>>>> protected Point getInitialSize() {
>>>> return new Point(382, 280);
>>>> }
>>>>
>>>> protected void configureShell(Shell newShell) {
>>>> super.configureShell(newShell);
>>>> newShell.setText("upload file");
>>>> }
>>>>
>>>> }
>>>>
>>>>
>>>> file upload sevlet:
>>>>
>>>> public class FileUploadServlet extends HttpServlet {
>>>> private static final long serialVersionUID = -7245361228773015964L;
>>>> private String uploadPath = "/upload/"; // server file repository
>>>> private String tempPath = "/upload/tmp/"; //temp file folder
>>>>
>>>> public void doPost(HttpServletRequest request, HttpServletResponse
>>>> response)
>>>> throws IOException, ServletException {
>>>> try {
>>>> DiskFileUpload fu = new DiskFileUpload();
>>>> // max file size
>>>> fu.setSizeMax(-1);
>>>> // buffer size
>>>> fu.setSizeThreshold(4096);
>>>> // temp path
>>>> fu.setRepositoryPath(tempPath);
>>>>
>>>> // get all uploa file
>>>> List fileItems = fu.parseRequest(request);
>>>> Iterator i = fileItems.iterator();
>>>> while (i.hasNext()) {
>>>> FileItem fi = (FileItem) i.next();
>>>> // get the upload file name
>>>> String fileName = fi.getName();
>>>> String sep = System.getProperty("file.separator");
>>>> int index = fileName.lastIndexOf(sep);
>>>> if(index >-1){
>>>> fileName = fileName.substring(fileName.lastIndexOf(sep));
>>>> }
>>>> fi.write(new File(uploadPath + fileName));
>>>> response.getWriter().println(fileName+"upload success");
>>>> }
>>>> } catch (Exception e) {
>>>> //do something?
>>>> e.printStackTrace();
>>>> }
>>>> }
>>>> public void init() throws ServletException {
>>>> if (!new File(uploadPath).isDirectory())
>>>> new File(uploadPath).mkdirs();
>>>> if (!new File(tempPath).isDirectory())
>>>> new File(tempPath).mkdirs();
>>>> }
>>>> }
>>>>
>>>> registe servlet:
>>>>
>>>>
>>>> public class HttpServiceTracker extends ServiceTracker {
>>>>
>>>> public HttpServiceTracker(BundleContext context) {
>>>> super(context, HttpService.class.getName(), null);
>>>> }
>>>>
>>>> public Object addingService(ServiceReference reference) {
>>>> final HttpService httpService = (HttpService) context
>>>> .getService(reference);
>>>> try {
>>>> //regist file upload servlet
>>>> HttpContext commonContext = new
>>>> BundleEntryHttpContext(context
>>>> .getBundle(), fileFolder);
>>>> httpService.registerResources(fileContext, "/",
>>>> commonContext);
>>>>
>>>> Servlet adaptedJspServlet = new
>>>> ContextPathServletAdaptor(
>>>> new FileUploadServlet(),
>>>> fileContext);
>>>> httpService.registerServlet(fileContext +
>>>> "/fileupload.file",
>>>> adaptedJspServlet, null, commonContext);
>>>>
>>>> } catch (Exception e) {
>>>> e.printStackTrace();
>>>> }
>>>> return httpService;
>>>> }
>>>>
>>>> public void removedService(ServiceReference reference, Object
>>>> service)
>>>> {
>>>> final HttpService httpService = (HttpService) service;
>>>> httpService.unregister(fileContext);
>>>> httpService.unregister(fileContext + "/fileupload.jsp");
>>>> super.removedService(reference, service);
>>>> }
>>>> }
>>>>
>>>> start servlet:
>>>>
>>>> add these code to the bundle start up method.
>>>> public void start(BundleContext context) throws Exception {
>>>> super.start(context);
>>>> plugin = this;
>>>> httpServiceTracker = new HttpServiceTracker(context);
>>>> httpServiceTracker.open();
>>>> System.out.println("IM resource servlet started...");
>>>> }
|
|
|
Re: Upload a file [message #66555 is a reply to message #66132] |
Fri, 14 December 2007 12:59   |
Eclipse User |
|
|
|
Originally posted by: just4lists.nospammail.net
Fixed by Tiago at CVS.
Best regards,
Joel Oliveira
"Rüdiger Herrmann" <rherrmann@innoopract.com> escreveu na mensagem
news:fjrbmf$164$1@build.eclipse.org...
> Tiago,
>
> the code I use (see attachment in my previous post) does the same as your
> snippet, but doesn't work.
> First of all isFinished() never returns true. But even if, according to
> the JavaDoc, the getLastFileUploaded() method returns the client path
> name. Besides it seems to never get assigned (Ctrl+Shift+G on
> lastFileUploaded field in Upload.java)
>
> Cheers,
> Rüdiger
>
> Tiago wrote:
>> You can use the following snipet to get the uploaded file name:
>>
>> Upload upload = new Upload(parent, SWT.NONE, null, true);
>> upload.addUploadListener(new UploadAdapter() {
>> public void uploadFinished(final UploadEvent uploadEvent) {
>> if (uploadEvent.isFinished()) {
>> String uploadedFileName = upload.getLastFileUploaded();
>> }
>> }
>> });
>>
>> Hope it helps.
>>
>> Tiago
>>
>> "Christian" <zerostress@libero.it> wrote in message
>> news:fjou7g$1on$1@build.eclipse.org...
>>> Hi,
>>>
>>> i confirm the same problem.
>>>
>>> Christian
>>>
>>>
>>> Rüdiger Herrmann ha scritto:
>>>> Hi,
>>>>
>>>> I am at it... but can't find a way to obtain the uploaded data.
>>>> From looking at the code, I seems to be written to a temp directory,
>>>> but
>>>> within the UploadListener I don't see a way to at least obtain the file
>>>> name. Am I missing something?
>>>> Attached is the code I wrote so far. It can be run as a new tab inside
>>>> the ControlsDemo, just past the code and add
>>>> new UploadTab( topFolder )
>>>> to ControlsDemo#createContent(Composite)
>>>> Of course you need to update the plug-in dependencies to include
>>>> org...upload;)
>>>>
>>>>
>>>> Cheers,
>>>> Rüdiger
>>>>
>>>> Joel Oliveira wrote:
>>>>> Waiting for validation from the core RAP Team. _:)
>>>>>
>>>>> "Setya" <jsetya@gmail.com> escreveu na mensagem
>>>>> news:d908a33130c626aa4f832cc470088ee7$1@www.eclipse.org...
>>>>>> Hi Joel,
>>>>>>
>>>>>> Thank you very much for your contribution on FileUpload widget. We
>>>>>> too need this widget badly. When can we expect this widget be
>>>>>> released officially (not through CVS) ?
>>>>>>
>>>>>> Regards,
>>>>>>
>>>>>> Setya
>>>>>>
>>
|
|
| | |
Re: Upload a file [message #67045 is a reply to message #66971] |
Wed, 19 December 2007 18:21   |
Eclipse User |
|
|
|
Originally posted by: rherrmann.innoopract.com
Hi Tiago,
custom events are currently not supported by RWT. To work around this
you can wrap the event execution in a Runnable and pass it to
ProcessActionRunner#add() like this:
ProcessActionRunner.add( new Runnable() {
public void run() {
// fire event
}
} );
Cheers,
Rüdiger
Tiago wrote:
> Hi Rüdiger,
>
> I've aparently located the problem. If fact there were two, some minor bug
> in the JS that was easily fixed and another one wich I'm having trouble in
> solving. It apears that at the end of my custom UploadEvent the screen is
> not "refreshed", so when you set the text or the image on the label they
> don't apear.
>
> Any tips regarding custom events and the lifecycle?
>
> Tiago
>
> "Rüdiger Herrmann" <rherrmann@innoopract.com> wrote in message
> news:fk613e$rqr$1@build.eclipse.org...
>> Hi,
>>
>> in order to validate the contribution, first thing would be to get an
>> example to work.
>> With the latest code from CVS HEAD, I am still not able to get the
>> upload widget to work. Could you have a look at the attached snippet, a
>> slightly changed variant of the previous one, and tell what's wrong?
>>
>> Note that uncommenting the event.isFinished() in line 42, which in my
>> case never returns true, doesn't solve the problem.
>>
>> The use-case of the snippet is to upload an image that should be
>> displayed in the label below the upload widget once the "upload" button
>> was pressed.
>>
>> Thanks,
>> Rüdiger
>>
>> Joel Oliveira wrote:
>>> Fixed by Tiago at CVS.
>>>
>>> Best regards,
>>>
>>> Joel Oliveira
>>>
>>> "Rüdiger Herrmann" <rherrmann@innoopract.com> escreveu na mensagem
>>> news:fjrbmf$164$1@build.eclipse.org...
>>>> Tiago,
>>>>
>>>> the code I use (see attachment in my previous post) does the same as
>>>> your snippet, but doesn't work.
>>>> First of all isFinished() never returns true. But even if, according
>>>> to the JavaDoc, the getLastFileUploaded() method returns the client
>>>> path name. Besides it seems to never get assigned (Ctrl+Shift+G on
>>>> lastFileUploaded field in Upload.java)
>>>>
>>>> Cheers,
>>>> Rüdiger
>>>>
>>>> Tiago wrote:
>>>>> You can use the following snipet to get the uploaded file name:
>>>>>
>>>>> Upload upload = new Upload(parent, SWT.NONE, null, true);
>>>>> upload.addUploadListener(new UploadAdapter() {
>>>>> public void uploadFinished(final UploadEvent uploadEvent) {
>>>>> if (uploadEvent.isFinished()) {
>>>>> String uploadedFileName = upload.getLastFileUploaded();
>>>>> }
>>>>> }
>>>>> });
>>>>>
>>>>> Hope it helps.
>>>>>
>>>>> Tiago
>>>>>
>>>>> "Christian" <zerostress@libero.it> wrote in message
>>>>> news:fjou7g$1on$1@build.eclipse.org...
>>>>>> Hi,
>>>>>>
>>>>>> i confirm the same problem.
>>>>>>
>>>>>> Christian
>>>>>>
>>>>>>
>>>>>> Rüdiger Herrmann ha scritto:
>>>>>>> Hi,
>>>>>>>
>>>>>>> I am at it... but can't find a way to obtain the uploaded data.
>>>>>>> From looking at the code, I seems to be written to a temp
>>>>>>> directory, but
>>>>>>> within the UploadListener I don't see a way to at least obtain the
>>>>>>> file
>>>>>>> name. Am I missing something?
>>>>>>> Attached is the code I wrote so far. It can be run as a new tab
>>>>>>> inside
>>>>>>> the ControlsDemo, just past the code and add
>>>>>>> new UploadTab( topFolder )
>>>>>>> to ControlsDemo#createContent(Composite)
>>>>>>> Of course you need to update the plug-in dependencies to include
>>>>>>> org...upload;)
>>>>>>>
>>>>>>>
>>>>>>> Cheers,
>>>>>>> Rüdiger
>>>>>>>
>>>>>>> Joel Oliveira wrote:
>>>>>>>> Waiting for validation from the core RAP Team. _:)
>>>>>>>>
>>>>>>>> "Setya" <jsetya@gmail.com> escreveu na mensagem
>>>>>>>> news:d908a33130c626aa4f832cc470088ee7$1@www.eclipse.org...
>>>>>>>>> Hi Joel,
>>>>>>>>>
>>>>>>>>> Thank you very much for your contribution on FileUpload widget. We
>>>>>>>>> too need this widget badly. When can we expect this widget be
>>>>>>>>> released officially (not through CVS) ?
>>>>>>>>>
>>>>>>>>> Regards,
>>>>>>>>>
>>>>>>>>> Setya
>>>>>>>>>
>>
>
>
> ------------------------------------------------------------ --------------------
>
>
>> /*********************************************************** ********************
>> * Copyright (c) 2007 Innoopract Informationssysteme GmbH.
>> * All rights reserved. This program and the accompanying materials
>> * are made available under the terms of the Eclipse Public License v1.0
>> * which accompanies this distribution, and is available at
>> * http://www.eclipse.org/legal/epl-v10.html
>> *
>> * Contributors:
>> * Innoopract Informationssysteme GmbH - initial API and implementation
>> ************************************************************ ******************/
>> package org.eclipse.rap.demo.controls;
>>
>> import java.io.*;
>>
>> import org.eclipse.rwt.graphics.Graphics;
>> import org.eclipse.rwt.widgets.*;
>> import org.eclipse.swt.SWT;
>> import org.eclipse.swt.custom.CTabFolder;
>> import org.eclipse.swt.graphics.Image;
>> import org.eclipse.swt.layout.GridData;
>> import org.eclipse.swt.layout.GridLayout;
>> import org.eclipse.swt.widgets.*;
>>
>> final class UploadTab extends ExampleTab {
>>
>> public UploadTab( final CTabFolder folder ) {
>> super( folder, "Upload" );
>> }
>>
>> protected void createStyleControls( final Composite parent ) {
>> }
>>
>> protected void createExampleControls( final Composite parent ) {
>> parent.setLayout( new GridLayout( 2, false ) );
>> final Upload upload = new Upload( parent, SWT.NONE, null, true );
>> upload.setLayoutData( new GridData( 300, SWT.DEFAULT ) );
>> final Label image = new Label( parent, SWT.NONE );
>> final Text txtDescription = new Text( parent, SWT.BORDER );
>> final Label lblDescription = new Label( parent, SWT.NONE );
>> upload.addUploadListener( new UploadAdapter() {
>> public void uploadFinished( final UploadEvent event ) {
>> if( event.isFinished() ) {
>> lblDescription.setText( txtDescription.getText() );
>> File clientFullName = new File( upload.getLastFileUploaded() );
>> image.setImage( readImage( clientFullName.getName() ) );
>> }
>> }
>> } );
>> }
>>
>> private static Image readImage( final String fileName ) {
>> Image result = null;
>> File tempDir = new File( System.getProperty( "java.io.tmpdir" ) );
>> File file = new File( tempDir, fileName );
>> try {
>> FileInputStream stream = new FileInputStream( file );
>> try {
>> result = Graphics.getImage( fileName, stream );
>> } finally {
>> stream.close();
>> }
>> } catch( IOException e ) {
>> e.printStackTrace();
>> }
>> return result;
>> }
>> }
>>
>
>
|
|
| |
Re: Upload a file [message #67214 is a reply to message #67153] |
Fri, 21 December 2007 10:30   |
Eclipse User |
|
|
|
Originally posted by: just4lists.nospammail.net
Committed at CVS.
Best regards and happy xmas!
Joel Oliveira
"Tiago" <tiago.bugzilla@gmail.com> escreveu na mensagem
news:fkdhbs$rd1$1@build.eclipse.org...
> Hi
>
> Worked great! Joel will commit to the CVS the fixed version soon.
>
> Thanks
>
> Tiago
>
> "Rüdiger Herrmann" <rherrmann@innoopract.com> wrote in message
> news:fkc92m$6gl$1@build.eclipse.org...
>> Hi Tiago,
>>
>> custom events are currently not supported by RWT. To work around this you
>> can wrap the event execution in a Runnable and pass it to
>> ProcessActionRunner#add() like this:
>>
>> ProcessActionRunner.add( new Runnable() {
>> public void run() {
>> // fire event
>> }
>> } );
>>
>> Cheers,
>> Rüdiger
>>
>> Tiago wrote:
>>> Hi Rüdiger,
>>>
>>> I've aparently located the problem. If fact there were two, some minor
>>> bug in the JS that was easily fixed and another one wich I'm having
>>> trouble in solving. It apears that at the end of my custom UploadEvent
>>> the screen is not "refreshed", so when you set the text or the image on
>>> the label they don't apear.
>>>
>>> Any tips regarding custom events and the lifecycle?
>>>
>>> Tiago
>>>
>>> "Rüdiger Herrmann" <rherrmann@innoopract.com> wrote in message
>>> news:fk613e$rqr$1@build.eclipse.org...
>>>> Hi,
>>>>
>>>> in order to validate the contribution, first thing would be to get an
>>>> example to work.
>>>> With the latest code from CVS HEAD, I am still not able to get the
>>>> upload widget to work. Could you have a look at the attached snippet, a
>>>> slightly changed variant of the previous one, and tell what's wrong?
>>>>
>>>> Note that uncommenting the event.isFinished() in line 42, which in my
>>>> case never returns true, doesn't solve the problem.
>>>>
>>>> The use-case of the snippet is to upload an image that should be
>>>> displayed in the label below the upload widget once the "upload" button
>>>> was pressed.
>>>>
>>>> Thanks,
>>>> Rüdiger
>>>>
>>>> Joel Oliveira wrote:
>>>>> Fixed by Tiago at CVS.
>>>>>
>>>>> Best regards,
>>>>>
>>>>> Joel Oliveira
>>>>>
>>>>> "Rüdiger Herrmann" <rherrmann@innoopract.com> escreveu na mensagem
>>>>> news:fjrbmf$164$1@build.eclipse.org...
>>>>>> Tiago,
>>>>>>
>>>>>> the code I use (see attachment in my previous post) does the same as
>>>>>> your snippet, but doesn't work.
>>>>>> First of all isFinished() never returns true. But even if, according
>>>>>> to the JavaDoc, the getLastFileUploaded() method returns the client
>>>>>> path name. Besides it seems to never get assigned (Ctrl+Shift+G on
>>>>>> lastFileUploaded field in Upload.java)
>>>>>>
>>>>>> Cheers,
>>>>>> Rüdiger
>>>>>>
>>>>>> Tiago wrote:
>>>>>>> You can use the following snipet to get the uploaded file name:
>>>>>>>
>>>>>>> Upload upload = new Upload(parent, SWT.NONE, null, true);
>>>>>>> upload.addUploadListener(new UploadAdapter() {
>>>>>>> public void uploadFinished(final UploadEvent uploadEvent) {
>>>>>>> if (uploadEvent.isFinished()) {
>>>>>>> String uploadedFileName = upload.getLastFileUploaded();
>>>>>>> }
>>>>>>> }
>>>>>>> });
>>>>>>>
>>>>>>> Hope it helps.
>>>>>>>
>>>>>>> Tiago
>>>>>>>
>>>>>>> "Christian" <zerostress@libero.it> wrote in message
>>>>>>> news:fjou7g$1on$1@build.eclipse.org...
>>>>>>>> Hi,
>>>>>>>>
>>>>>>>> i confirm the same problem.
>>>>>>>>
>>>>>>>> Christian
>>>>>>>>
>>>>>>>>
>>>>>>>> Rüdiger Herrmann ha scritto:
>>>>>>>>> Hi,
>>>>>>>>>
>>>>>>>>> I am at it... but can't find a way to obtain the uploaded data.
>>>>>>>>> From looking at the code, I seems to be written to a temp
>>>>>>>>> directory, but
>>>>>>>>> within the UploadListener I don't see a way to at least obtain the
>>>>>>>>> file
>>>>>>>>> name. Am I missing something?
>>>>>>>>> Attached is the code I wrote so far. It can be run as a new tab
>>>>>>>>> inside
>>>>>>>>> the ControlsDemo, just past the code and add
>>>>>>>>> new UploadTab( topFolder )
>>>>>>>>> to ControlsDemo#createContent(Composite)
>>>>>>>>> Of course you need to update the plug-in dependencies to include
>>>>>>>>> org...upload;)
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> Cheers,
>>>>>>>>> Rüdiger
>>>>>>>>>
>>>>>>>>> Joel Oliveira wrote:
>>>>>>>>>> Waiting for validation from the core RAP Team. _:)
>>>>>>>>>>
>>>>>>>>>> "Setya" <jsetya@gmail.com> escreveu na mensagem
>>>>>>>>>> news:d908a33130c626aa4f832cc470088ee7$1@www.eclipse.org...
>>>>>>>>>>> Hi Joel,
>>>>>>>>>>>
>>>>>>>>>>> Thank you very much for your contribution on FileUpload widget.
>>>>>>>>>>> We
>>>>>>>>>>> too need this widget badly. When can we expect this widget be
>>>>>>>>>>> released officially (not through CVS) ?
>>>>>>>>>>>
>>>>>>>>>>> Regards,
>>>>>>>>>>>
>>>>>>>>>>> Setya
>>>>>>>>>>>
>>>>
>>>
>>>
>>> ------------------------------------------------------------ --------------------
>>>
>>>
>>>> /*********************************************************** ********************
>>>> * Copyright (c) 2007 Innoopract Informationssysteme GmbH.
>>>> * All rights reserved. This program and the accompanying materials
>>>> * are made available under the terms of the Eclipse Public License v1.0
>>>> * which accompanies this distribution, and is available at
>>>> * http://www.eclipse.org/legal/epl-v10.html
>>>> *
>>>> * Contributors:
>>>> * Innoopract Informationssysteme GmbH - initial API and
>>>> implementation
>>>> ************************************************************ ******************/
>>>> package org.eclipse.rap.demo.controls;
>>>>
>>>> import java.io.*;
>>>>
>>>> import org.eclipse.rwt.graphics.Graphics;
>>>> import org.eclipse.rwt.widgets.*;
>>>> import org.eclipse.swt.SWT;
>>>> import org.eclipse.swt.custom.CTabFolder;
>>>> import org.eclipse.swt.graphics.Image;
>>>> import org.eclipse.swt.layout.GridData;
>>>> import org.eclipse.swt.layout.GridLayout;
>>>> import org.eclipse.swt.widgets.*;
>>>>
>>>> final class UploadTab extends ExampleTab {
>>>>
>>>> public UploadTab( final CTabFolder folder ) {
>>>> super( folder, "Upload" );
>>>> }
>>>>
>>>> protected void createStyleControls( final Composite parent ) {
>>>> }
>>>>
>>>> protected void createExampleControls( final Composite parent ) {
>>>> parent.setLayout( new GridLayout( 2, false ) );
>>>> final Upload upload = new Upload( parent, SWT.NONE, null, true );
>>>> upload.setLayoutData( new GridData( 300, SWT.DEFAULT ) );
>>>> final Label image = new Label( parent, SWT.NONE );
>>>> final Text txtDescription = new Text( parent, SWT.BORDER );
>>>> final Label lblDescription = new Label( parent, SWT.NONE );
>>>> upload.addUploadListener( new UploadAdapter() {
>>>> public void uploadFinished( final UploadEvent event ) {
>>>> if( event.isFinished() ) {
>>>> lblDescription.setText( txtDescription.getText() );
>>>> File clientFullName = new File(
>>>> upload.getLastFileUploaded() );
>>>> image.setImage( readImage( clientFullName.getName() ) );
>>>> }
>>>> }
>>>> } );
>>>> }
>>>>
>>>> private static Image readImage( final String fileName ) {
>>>> Image result = null;
>>>> File tempDir = new File( System.getProperty( "java.io.tmpdir" ) );
>>>> File file = new File( tempDir, fileName );
>>>> try {
>>>> FileInputStream stream = new FileInputStream( file );
>>>> try {
>>>> result = Graphics.getImage( fileName, stream );
>>>> } finally {
>>>> stream.close();
>>>> }
>>>> } catch( IOException e ) {
>>>> e.printStackTrace();
>>>> }
>>>> return result;
>>>> }
>>>> }
>>>>
>>>
>
|
|
|
Re: Upload a file [message #67642 is a reply to message #67214] |
Tue, 01 January 2008 21:18   |
Eclipse User |
|
|
|
Originally posted by: chenmin827.126.com
On Fri, 21 Dec 2007 15:30:59 +0000, Joel Oliveira wrote:
> Committed at CVS.
>
> Best regards and happy xmas!
>
> Joel Oliveira
>
> "Tiago" <tiago.bugzilla@gmail.com> escreveu na mensagem
> news:fkdhbs$rd1$1@build.eclipse.org...
>> Hi
>>
>> Worked great! Joel will commit to the CVS the fixed version soon.
>>
>> Thanks
>>
>> Tiago
>>
>> "Rüdiger Herrmann" <rherrmann@innoopract.com> wrote in message
>> news:fkc92m$6gl$1@build.eclipse.org...
>>> Hi Tiago,
>>>
>>> custom events are currently not supported by RWT. To work around this you
>>> can wrap the event execution in a Runnable and pass it to
>>> ProcessActionRunner#add() like this:
>>>
>>> ProcessActionRunner.add( new Runnable() {
>>> public void run() {
>>> // fire event
>>> }
>>> } );
>>>
>>> Cheers,
>>> Rüdiger
>>>
>>> Tiago wrote:
>>>> Hi Rüdiger,
>>>>
>>>> I've aparently located the problem. If fact there were two, some minor
>>>> bug in the JS that was easily fixed and another one wich I'm having
>>>> trouble in solving. It apears that at the end of my custom UploadEvent
>>>> the screen is not "refreshed", so when you set the text or the image on
>>>> the label they don't apear.
>>>>
>>>> Any tips regarding custom events and the lifecycle?
>>>>
>>>> Tiago
>>>>
>>>> "Rüdiger Herrmann" <rherrmann@innoopract.com> wrote in message
>>>> news:fk613e$rqr$1@build.eclipse.org...
>>>>> Hi,
>>>>>
>>>>> in order to validate the contribution, first thing would be to get an
>>>>> example to work.
>>>>> With the latest code from CVS HEAD, I am still not able to get the
>>>>> upload widget to work. Could you have a look at the attached snippet, a
>>>>> slightly changed variant of the previous one, and tell what's wrong?
>>>>>
>>>>> Note that uncommenting the event.isFinished() in line 42, which in my
>>>>> case never returns true, doesn't solve the problem.
>>>>>
>>>>> The use-case of the snippet is to upload an image that should be
>>>>> displayed in the label below the upload widget once the "upload" button
>>>>> was pressed.
>>>>>
>>>>> Thanks,
>>>>> Rüdiger
>>>>>
>>>>> Joel Oliveira wrote:
>>>>>> Fixed by Tiago at CVS.
>>>>>>
>>>>>> Best regards,
>>>>>>
>>>>>> Joel Oliveira
>>>>>>
>>>>>> "Rüdiger Herrmann" <rherrmann@innoopract.com> escreveu na mensagem
>>>>>> news:fjrbmf$164$1@build.eclipse.org...
>>>>>>> Tiago,
>>>>>>>
>>>>>>> the code I use (see attachment in my previous post) does the same as
>>>>>>> your snippet, but doesn't work.
>>>>>>> First of all isFinished() never returns true. But even if, according
>>>>>>> to the JavaDoc, the getLastFileUploaded() method returns the client
>>>>>>> path name. Besides it seems to never get assigned (Ctrl+Shift+G on
>>>>>>> lastFileUploaded field in Upload.java)
>>>>>>>
>>>>>>> Cheers,
>>>>>>> Rüdiger
>>>>>>>
>>>>>>> Tiago wrote:
>>>>>>>> You can use the following snipet to get the uploaded file name:
>>>>>>>>
>>>>>>>> Upload upload = new Upload(parent, SWT.NONE, null, true);
>>>>>>>> upload.addUploadListener(new UploadAdapter() {
>>>>>>>> public void uploadFinished(final UploadEvent uploadEvent) {
>>>>>>>> if (uploadEvent.isFinished()) {
>>>>>>>> String uploadedFileName = upload.getLastFileUploaded();
>>>>>>>> }
>>>>>>>> }
>>>>>>>> });
>>>>>>>>
>>>>>>>> Hope it helps.
>>>>>>>>
>>>>>>>> Tiago
>>>>>>>>
>>>>>>>> "Christian" <zerostress@libero.it> wrote in message
>>>>>>>> news:fjou7g$1on$1@build.eclipse.org...
>>>>>>>>> Hi,
>>>>>>>>>
>>>>>>>>> i confirm the same problem.
>>>>>>>>>
>>>>>>>>> Christian
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> Rüdiger Herrmann ha scritto:
>>>>>>>>>> Hi,
>>>>>>>>>>
>>>>>>>>>> I am at it... but can't find a way to obtain the uploaded data.
>>>>>>>>>> From looking at the code, I seems to be written to a temp
>>>>>>>>>> directory, but
>>>>>>>>>> within the UploadListener I don't see a way to at least obtain the
>>>>>>>>>> file
>>>>>>>>>> name. Am I missing something?
>>>>>>>>>> Attached is the code I wrote so far. It can be run as a new tab
>>>>>>>>>> inside
>>>>>>>>>> the ControlsDemo, just past the code and add
>>>>>>>>>> new UploadTab( topFolder )
>>>>>>>>>> to ControlsDemo#createContent(Composite)
>>>>>>>>>> Of course you need to update the plug-in dependencies to include
>>>>>>>>>> org...upload;)
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> Cheers,
>>>>>>>>>> Rüdiger
>>>>>>>>>>
>>>>>>>>>> Joel Oliveira wrote:
>>>>>>>>>>> Waiting for validation from the core RAP Team. _:)
>>>>>>>>>>>
>>>>>>>>>>> "Setya" <jsetya@gmail.com> escreveu na mensagem
>>>>>>>>>>> news:d908a33130c626aa4f832cc470088ee7$1@www.eclipse.org...
>>>>>>>>>>>> Hi Joel,
>>>>>>>>>>>>
>>>>>>>>>>>> Thank you very much for your contribution on FileUpload widget.
>>>>>>>>>>>> We
>>>>>>>>>>>> too need this widget badly. When can we expect this widget be
>>>>>>>>>>>> released officially (not through CVS) ?
>>>>>>>>>>>>
>>>>>>>>>>>> Regards,
>>>>>>>>>>>>
>>>>>>>>>>>> Setya
>>>>>>>>>>>>
>>>>>
>>>>
>>>>
>>>> ------------------------------------------------------------ --------------------
>>>>
>>>>
>>>>> /*********************************************************** ********************
>>>>> * Copyright (c) 2007 Innoopract Informationssysteme GmbH.
>>>>> * All rights reserved. This program and the accompanying materials
>>>>> * are made available under the terms of the Eclipse Public License v1.0
>>>>> * which accompanies this distribution, and is available at
>>>>> * http://www.eclipse.org/legal/epl-v10.html
>>>>> *
>>>>> * Contributors:
>>>>> * Innoopract Informationssysteme GmbH - initial API and
>>>>> implementation
>>>>> ************************************************************ ******************/
>>>>> package org.eclipse.rap.demo.controls;
>>>>>
>>>>> import java.io.*;
>>>>>
>>>>> import org.eclipse.rwt.graphics.Graphics;
>>>>> import org.eclipse.rwt.widgets.*;
>>>>> import org.eclipse.swt.SWT;
>>>>> import org.eclipse.swt.custom.CTabFolder;
>>>>> import org.eclipse.swt.graphics.Image;
>>>>> import org.eclipse.swt.layout.GridData;
>>>>> import org.eclipse.swt.layout.GridLayout;
>>>>> import org.eclipse.swt.widgets.*;
>>>>>
>>>>> final class UploadTab extends ExampleTab {
>>>>>
>>>>> public UploadTab( final CTabFolder folder ) {
>>>>> super( folder, "Upload" );
>>>>> }
>>>>>
>>>>> protected void createStyleControls( final Composite parent ) {
>>>>> }
>>>>>
>>>>> protected void createExampleControls( final Composite parent ) {
>>>>> parent.setLayout( new GridLayout( 2, false ) );
>>>>> final Upload upload = new Upload( parent, SWT.NONE, null, true );
>>>>> upload.setLayoutData( new GridData( 300, SWT.DEFAULT ) );
>>>>> final Label image = new Label( parent, SWT.NONE );
>>>>> final Text txtDescription = new Text( parent, SWT.BORDER );
>>>>> final Label lblDescription = new Label( parent, SWT.NONE );
>>>>> upload.addUploadListener( new UploadAdapter() {
>>>>> public void uploadFinished( final UploadEvent event ) {
>>>>> if( event.isFinished() ) {
>>>>> lblDescription.setText( txtDescription.getText() );
>>>>> File clientFullName = new File(
>>>>> upload.getLastFileUploaded() );
>>>>> image.setImage( readImage( clientFullName.getName() ) );
>>>>> }
>>>>> }
>>>>> } );
>>>>> }
>>>>>
>>>>> private static Image readImage( final String fileName ) {
>>>>> Image result = null;
>>>>> File tempDir = new File( System.getProperty( "java.io.tmpdir" ) );
>>>>> File file = new File( tempDir, fileName );
>>>>> try {
>>>>> FileInputStream stream = new FileInputStream( file );
>>>>> try {
>>>>> result = Graphics.getImage( fileName, stream );
>>>>> } finally {
>>>>> stream.close();
>>>>> }
>>>>> } catch( IOException e ) {
>>>>> e.printStackTrace();
>>>>> }
>>>>> return result;
>>>>> }
>>>>> }
>>>>>
>>>>
>>
I have a question about upload widget: Progress bar dispalys normally when the project is lanuched in Eclipse; when the same project is deployed to Jetty composite, no progress displays when running. But no error message in this progress, and the file can be sucessfully uploaded.
Is this a known bug ?
Thanks and Regards,
cheney
|
|
| | |
Re: Upload a file [message #69854 is a reply to message #67214] |
Fri, 11 January 2008 09:22  |
Eclipse User |
|
|
|
Originally posted by: cheney_chen.i-len.com
I have a new question of the upload widget.First,I run the application with
the widget,then steps to reproduce:
1.Launch the application in Chinese version of Firefox;
2.Select a folder and click Upload;
3.Click Browse button to locate file.
Actual Result:
File Upload dialog does not appear.
Expected Result:
File Upload dialog should appear, allowing user to select file to be
uploaded.
Other Info:
The problem does not exist in English version.
Platform:
Simplified Chinese Browser: Firefox 2.0.0.6/Firefox 2.0.0.11
English Browser: Firefox_Portable_2.0.0.6/Firefox 2.0.0.11
can anyone fix the bug?
Thank and Regards,
Cheney
|
|
|
Goto Forum:
Current Time: Sun May 11 12:56:04 EDT 2025
Powered by FUDForum. Page generated in 0.07898 seconds
|