Package io.muserver
Interface UploadedFile
-
public interface UploadedFile
A 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.File
asFile()
Gets a copy of the file.java.io.InputStream
asStream()
Gets the uploaded file as a stream.java.lang.String
asString()
Returns the contents of the file as a String, decoded using UTF-8java.lang.String
contentType()
Gets the media type of the file as specified by the client, for exampleimage/jpeg
java.lang.String
extension()
Gets the extension of the file as it was on the client's computer.java.lang.String
filename()
Gets the original name of the file on the client's computer.void
saveTo(java.io.File dest)
Saves the file to the specified destination.long
size()
Gets the size of the file.
-
-
-
Method Detail
-
asFile
java.io.File asFile() throws java.io.IOException
Gets 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.IOException
Returns 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.IOException
Gets 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.IOException
Saves 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.IOException
Gets the uploaded file as a stream.- Returns:
- The file stream.
- Throws:
java.io.IOException
- If there is an error reading the file.
-
-