Package io.muserver
Interface UploadedFile
-
public interface UploadedFileA file uploaded by the user, for example with an<input type="file" name="name">input field in a multipart form.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description byte[]asBytes()Gets the file contents as a byte array.java.io.FileasFile()Gets a copy of the file.java.io.InputStreamasStream()Gets the uploaded file as a stream.java.lang.StringasString()Returns the contents of the file as a String, decoded using UTF-8java.lang.StringcontentType()Gets the media type of the file as specified by the client, for exampleimage/jpegjava.lang.Stringextension()Gets the extension of the file as it was on the client's computer.java.lang.Stringfilename()Gets the original name of the file on the client's computer.voidsaveTo(java.io.File dest)Saves the file to the specified destination.longsize()Gets the size of the file.
-
-
-
Method Detail
-
asFile
java.io.File asFile() throws java.io.IOExceptionGets a copy of the file. This has been uploaded to the server and saved locally.- Returns:
- Returns a File object pointing to the uploaded file.
- Throws:
java.io.IOException- If an error while saving file.
-
asString
java.lang.String asString() throws java.io.IOExceptionReturns the contents of the file as a String, decoded using UTF-8- Returns:
- The string contents of the file.
- Throws:
java.io.IOException- If an error reading the file.
-
asBytes
byte[] asBytes() throws java.io.IOExceptionGets the file contents as a byte array.- Returns:
- The bytes in the file.
- Throws:
java.io.IOException- If any error reading the bytes.
-
contentType
java.lang.String contentType()
Gets the media type of the file as specified by the client, for exampleimage/jpeg- Returns:
- The media type of the file.
-
filename
java.lang.String filename()
Gets the original name of the file on the client's computer. Does not include the path.- Returns:
- A file name with extension
-
extension
java.lang.String extension()
Gets the extension of the file as it was on the client's computer.- Returns:
- A string such as "jpg" or an empty string if there was no extension.
-
saveTo
void saveTo(java.io.File dest) throws java.io.IOExceptionSaves the file to the specified destination. Parent directories will be created if they do not exist.- Parameters:
dest- The destination to save to.- Throws:
java.io.IOException- If there is an error saving the file.
-
size
long size()
Gets the size of the file.- Returns:
- The file size.
-
asStream
java.io.InputStream asStream() throws java.io.IOExceptionGets the uploaded file as a stream.- Returns:
- The file stream.
- Throws:
java.io.IOException- If there is an error reading the file.
-
-