Package com.facilita.fc.web
Class FileElement
- java.lang.Object
-
- com.facilita.fc.web.HtmlElement
-
- com.facilita.fc.web.InputElement
-
- com.facilita.fc.web.FileElement
-
public class FileElement extends InputElement
Represents anInputElement
which is a file select control. A file select control allows the user to select one or more files to upload.e.g.
<input name="uploadedfile" type="file" />
If files are added to a
FileElement
object, they will be uploaded when the containingForm
is sent to the web server.- See Also:
Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.facilita.fc.web.InputElement
InputElement.InputElementType
-
-
Constructor Summary
Constructors Constructor Description FileElement(long cPtr, boolean cMemoryOwn)
For internal use only.FileElement(java.lang.String elementName)
Creates aFileElement
object with the specified name
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addFile(java.lang.String filename, java.lang.String path)
Adds a file to the list of files to upload.void
addFile(java.lang.String filename, java.lang.String path, java.lang.String contentType)
Adds a file to the list of files to upload.void
addFile(java.lang.String filename, java.lang.String path, java.lang.String contentType, java.lang.String contentTransferEncoding)
Adds a file to the list of files to upload.void
clearFiles()
Clears the list of files to be uploaded.HtmlElement
clone()
Creates a copy of this HTML element.void
delete()
static long
getCPtr(FileElement obj)
For internal use only.java.lang.String
getMultipartBoundary()
Gets theString
that will be used as the boundary between files (including the--
prefix), when encoding this element as multipart/form-data.void
removeFile(java.lang.String filename)
Removes a file from the list of files to be uploaded.void
setMultipartBoundary(java.lang.String boundary)
Sets theString
that will be used as the boundary between files (including the--
prefix), when encoding this element as multipart/form-data.-
Methods inherited from class com.facilita.fc.web.InputElement
getCPtr, getType, isChecked, isSubmitted, isSuccessfulControl, makeFrom, setChecked, setSubmitted
-
Methods inherited from class com.facilita.fc.web.HtmlElement
getAfterEndTagPosition, getAfterStartTagPosition, getAttribute, getAttributes, getCharEncoding, getContent, getContentPosition, getCPtr, getId, getName, getTag, getValue, hasAttribute, isDisabled, removeAttribute, setAttribute, setAttribute, setCharEncoding, setContent, setDisabled, setId, setName, setValue
-
-
-
-
Constructor Detail
-
FileElement
public FileElement(long cPtr, boolean cMemoryOwn)
For internal use only. Of no interest to the user.- Parameters:
cPtr
- pointer to the CPP wrapped objectcMemoryOwn
- indicates if this object is responsible for memory management of the CPP object
-
FileElement
public FileElement(java.lang.String elementName)
Creates aFileElement
object with the specified name- Parameters:
elementName
- the name attribute of the FileElement
-
-
Method Detail
-
getCPtr
public static long getCPtr(FileElement obj)
For internal use only. Of no interest to the user.- Parameters:
obj
- a reference to an object of this class- Returns:
- a long containing the address of the CPP wrapped object
-
delete
public void delete()
- Overrides:
delete
in classInputElement
-
addFile
public void addFile(java.lang.String filename, java.lang.String path, java.lang.String contentType, java.lang.String contentTransferEncoding) throws java.io.UnsupportedEncodingException
Adds a file to the list of files to upload. It will be uploaded when theForm
which contains thisFileElement
is sent to the web server.- Parameters:
filename
- the name of the filepath
- the location of the file on disk. This can either be an absolute path, or a relative path. If it is a relative path, then it is relative to thedata/Files
directory for the current injectorcontentType
- the Content-Type to specify when sending this file (e.g."text/plain"
,"image/gif"
)contentTransferEncoding
- the Content-Transfer-Encoding to specify when sending this file (e.g."binary"
)- Throws:
java.io.UnsupportedEncodingException
- The specified encoding is not supported.
-
addFile
public void addFile(java.lang.String filename, java.lang.String path, java.lang.String contentType) throws java.io.UnsupportedEncodingException
Adds a file to the list of files to upload. It will be uploaded when theForm
which contains thisFileElement
is sent to the web server.The default Content-Transfer-Encoding is
""
.- Parameters:
filename
- the name of the filepath
- the location of the file on disk. This can either be an absolute path, or a relative path. If it is a relative path, then it is relative to thedata/Files
directory for the current injectorcontentType
- the Content-Type to specify when sending this file (e.g."text/plain"
,"image/gif"
)- Throws:
java.io.UnsupportedEncodingException
- The specified encoding is not supported.
-
addFile
public void addFile(java.lang.String filename, java.lang.String path) throws java.io.UnsupportedEncodingException
Adds a file to the list of files to upload. It will be uploaded when theForm
which contains thisFileElement
is sent to the web server.The default Content-Type is
"text/plain"
, and the default Content-Transfer-Encoding is""
.- Parameters:
filename
- the name of the filepath
- the location of the file on disk. This can either be an absolute path, or a relative path. If it is a relative path, then it is relative to thedata/Files
directory for the current injector- Throws:
java.io.UnsupportedEncodingException
- The specified encoding is not supported.
-
removeFile
public void removeFile(java.lang.String filename) throws java.io.UnsupportedEncodingException
Removes a file from the list of files to be uploaded.- Parameters:
filename
- the name of the file to remove from the list- Throws:
java.io.UnsupportedEncodingException
- The specified encoding is not supported.
-
clearFiles
public void clearFiles()
Clears the list of files to be uploaded.
-
getMultipartBoundary
public java.lang.String getMultipartBoundary()
Gets theString
that will be used as the boundary between files (including the--
prefix), when encoding this element as multipart/form-data.e.g. for this POST data message body:
--multipart-form-boundary Content-Disposition: form-data; name="input1" value1 --multipart-form-boundary Content-Disposition: form-data; name="files-to-upload[]" Content-Type: multipart/mixed; boundary=multipart-file-boundary --multipart-file-boundary Content-Disposition: file; filename="image.bmp" Content-Type: image/bmp (binary image data) --multipart-file-boundary Content-Disposition: file; filename="image2.bmp" Content-Type: image/bmp (binary image data) --multipart-file-boundary-- --multipart-form-boundary--
form.getFileElement("files-to-upload[]").getMultipartBoundary()
will return"--multipart-file-boundary"
- Returns:
- the
String
that will be used as the boundary between files (including the--
prefix), when encoding this element as multipart/form-data - See Also:
setMultipartBoundary(String)
-
setMultipartBoundary
public void setMultipartBoundary(java.lang.String boundary)
Sets theString
that will be used as the boundary between files (including the--
prefix), when encoding this element as multipart/form-data.e.g.
The POST data message body contains:// Populate form with data Form form = previousResponse.extractForm("myForm"); form.getInputElement("input1").setValue("value1"); form.getFileElement("files-to-upload[]").addFile("image.bmp", "C:\\dataFiles\\image.bmp", "image/bmp"); form.getFileElement("files-to-upload[]").addFile("image2.bmp", "C:\\dataFiles\\image2.bmp", "image/bmp"); // Set the multipart boundary for the FileElement form.getFileElement("files-to-upload[]").setMultipartBoundary("--multipart-file-boundary"); // Send the POST request Request request = getWebBrowser().createRequest(HttpMethod.POST, myUrl); request.setMessageBody(form); Response response = request.send();
--multipart-form-boundary Content-Disposition: form-data; name="input1" value1 --multipart-form-boundary Content-Disposition: form-data; name="files-to-upload[]" Content-Type: multipart/mixed; boundary=multipart-file-boundary --multipart-file-boundary Content-Disposition: file; filename="image.bmp" Content-Type: image/bmp (binary image data) --multipart-file-boundary Content-Disposition: file; filename="image2.bmp" Content-Type: image/bmp (binary image data) --multipart-file-boundary-- --multipart-form-boundary--
- Parameters:
boundary
- theString
that will be used as the boundary between files (including the--
prefix), when encoding this element as multipart/form-data- See Also:
getMultipartBoundary()
-
clone
public HtmlElement clone()
Description copied from class:HtmlElement
Creates a copy of this HTML element.- Overrides:
clone
in classInputElement
- Returns:
- a new
HtmlElement
object which is an exact copy of this HTML element
-
-