Package jmri.util
Class MultipartMessage
java.lang.Object
jmri.util.MultipartMessage
Sends multi-part HTTP POST requests to a web server
This file is part of JMRI.
Based on http://www.codejava.net/java-se/networking/upload-files-by-sending-multipart-request-programmatically
This file is part of JMRI.
JMRI is free software; you can redistribute it and/or modify it under the terms of version 2 of the GNU General Public License as published by the Free Software Foundation. See the "COPYING" file for a copy of this license.
JMRI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
Constructor Summary
ConstructorsConstructorDescriptionMultipartMessage(String requestURL, String charSet) Constructor initialises a new HTTP POST request with content type set to 'multipart/form-data'. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddFilePart(String fieldName, File uploadFile) Adds an upload file section to the request.voidaddFilePart(String fieldName, File uploadFile, String fileType) Adds an upload file section to the request.voidaddFormField(String name, String value) Adds form field data to the requestvoidaddHeaderField(String name, String value) Adds a header field to the requestfinish()Finalise and send MultipartMessage to end-point.
-
Constructor Details
-
MultipartMessage
Constructor initialises a new HTTP POST request with content type set to 'multipart/form-data'.This allows for additional binary data to be uploaded.
- Parameters:
requestURL- URL to which this request should be sentcharSet- character set encoding of this message- Throws:
IOException- ifOutputStreamcannot be createdURISyntaxException- if the requestURL has wrong syntax
-
-
Method Details
-
addFormField
Adds form field data to the request- Parameters:
name- field namevalue- field value
-
addFilePart
Adds an upload file section to the request. MIME type of the file is determined based on the file extension.- Parameters:
fieldName- name attribute in form <input name="{fieldName}" type="file" />uploadFile- file to be uploaded- Throws:
IOException- if problem adding file to request
-
addFilePart
Adds an upload file section to the request. MIME type of the file is explicitly set.- Parameters:
fieldName- name attribute in form <input name="{fieldName}" type="file" />uploadFile- file to be uploadedfileType- MIME type of file- Throws:
IOException- if problem adding file to request
-
addHeaderField
Adds a header field to the request- Parameters:
name- name of header fieldvalue- value of header field
-
finish
Finalise and send MultipartMessage to end-point.- Returns:
- Responses from end-point as a List of Strings
- Throws:
IOException- if problem sending MultipartMessage to end-point
-