Generated a basic sample to test the UploadItem component but I don't receive a multipart request with the selected file to be uploaded.
I don't know what I'm doing wrong in this case. Can you help me? Thank you.
Using: SmartClient Version: v10.0p_2015-10-06/LGPL Development Only (built 2015-10-06)
Browser: Version 45.0.2454.101 m
Steps to reproduce:
Select a file and click "Save form"
Check wich messages was thrown by the servlet handling the file upload
SmartGWT client code:
Servlet code:
I don't know what I'm doing wrong in this case. Can you help me? Thank you.
Using: SmartClient Version: v10.0p_2015-10-06/LGPL Development Only (built 2015-10-06)
Browser: Version 45.0.2454.101 m
Steps to reproduce:
Select a file and click "Save form"
Check wich messages was thrown by the servlet handling the file upload
SmartGWT client code:
Code:
import com.google.gwt.core.client.EntryPoint; import com.smartgwt.client.data.DataSource; import com.smartgwt.client.data.OperationBinding; import com.smartgwt.client.data.fields.DataSourceBinaryField; import com.smartgwt.client.data.fields.DataSourceSequenceField; import com.smartgwt.client.types.DSDataFormat; import com.smartgwt.client.types.DSOperationType; import com.smartgwt.client.types.DSProtocol; import com.smartgwt.client.types.Encoding; import com.smartgwt.client.widgets.form.DynamicForm; import com.smartgwt.client.widgets.form.fields.CancelItem; import com.smartgwt.client.widgets.form.fields.SubmitItem; import com.smartgwt.client.widgets.form.fields.UploadItem; import com.smartgwt.client.widgets.layout.VLayout; public class FileItemTestCase implements EntryPoint { @Override public void onModuleLoad() { UploadItem multiFilePicker = new UploadItem("Attachment"); SubmitItem submit = new SubmitItem("submit", "Save Form"); CancelItem cancel = new CancelItem("cancel", "Clear Form"); MessageDataSource dataSource = new MessageDataSource(); DynamicForm dynamicForm = new DynamicForm(); dynamicForm.setEncoding(Encoding.MULTIPART); dynamicForm.setDataSource(dataSource); dynamicForm.setFields(multiFilePicker, submit, cancel); VLayout topLayout = new VLayout(); topLayout.addMember(dynamicForm); topLayout.draw(); } } class MessageDataSource extends DataSource { public MessageDataSource() { super(); setID("messageDataSource"); setDataURL("fileUploadServlet"); DataSourceSequenceField id = new DataSourceSequenceField("Id"); id.setPrimaryKey(true); id.setHidden(true); DataSourceBinaryField attachment = new DataSourceBinaryField("Attachment"); OperationBinding fetch = new OperationBinding(); fetch.setOperationType(DSOperationType.FETCH); fetch.setDataProtocol(DSProtocol.GETPARAMS); OperationBinding add = new OperationBinding(); add.setOperationType(DSOperationType.ADD); add.setDataProtocol(DSProtocol.POSTMESSAGE); OperationBinding update = new OperationBinding(); update.setOperationType(DSOperationType.UPDATE); update.setDataProtocol(DSProtocol.POSTMESSAGE); OperationBinding remove = new OperationBinding(); remove.setOperationType(DSOperationType.REMOVE); remove.setDataProtocol(DSProtocol.POSTMESSAGE); setOperationBindings(fetch, add, update, remove); setDataFormat(DSDataFormat.JSON); setFields(id, attachment); } }
Code:
package com.testcases.fileUploadServlet; import java.io.IOException; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.fileupload.servlet.ServletFileUpload; public class FileUploadServlet extends HttpServlet { @Override protected void doPost(HttpServletRequest req, HttpServletResponse res) { String bodyContent = "<html><body>"; if (ServletFileUpload.isMultipartContent(req)) { bodyContent += "Multipart request"; } else { bodyContent += "Not multipart request"; } bodyContent += "</body><html>"; ServletOutputStream os; try { os = res.getOutputStream(); os.write(bodyContent.getBytes()); } catch (IOException e) { e.printStackTrace(); } } }
Comment