public class JsFileReader extends JsElementalMixinBase implements FileReader
DONE, EMPTY, LOADING
SVG_ZOOMANDPAN_DISABLE, SVG_ZOOMANDPAN_MAGNIFY, SVG_ZOOMANDPAN_UNKNOWN
Modifier | Constructor and Description |
---|---|
protected |
JsFileReader() |
Modifier and Type | Method and Description |
---|---|
void |
abort()
Aborts the read operation.
|
JsFileError |
getError()
The error that occurred while reading the file.
|
EventListener |
getOnabort()
Called when the read operation is aborted.
|
EventListener |
getOnerror()
Called when an error occurs.
|
EventListener |
getOnload()
Called when the read operation is successfully completed.
|
EventListener |
getOnloadend()
Called when the read is completed, whether successful or not.
|
EventListener |
getOnloadstart()
Called when reading the data is about to begin.
|
EventListener |
getOnprogress()
Called periodically while the data is being read.
|
int |
getReadyState()
Indicates the state of the
FileReader . |
Object |
getResult()
The file's contents.
|
void |
readAsArrayBuffer(Blob blob)
|
void |
readAsBinaryString(Blob blob)
|
void |
readAsDataURL(Blob blob)
|
void |
readAsText(Blob blob)
Starts reading the specified blob's contents.
|
void |
readAsText(Blob blob,
String encoding)
Starts reading the specified blob's contents.
|
void |
setOnabort(EventListener listener) |
void |
setOnerror(EventListener listener) |
void |
setOnload(EventListener listener) |
void |
setOnloadend(EventListener listener) |
void |
setOnloadstart(EventListener listener) |
void |
setOnprogress(EventListener listener) |
addEventListener, addEventListener, beginElement, beginElementAt, dispatchEvent, endElement, endElementAt, getAnimatedClassName, getAnimatedHeight, getAnimatedHref, getAnimatedResult, getAnimatedTransform, getAnimatedWidth, getAnimatedX, getAnimatedY, getBBox, getChildElementCount, getCTM, getExternalResourcesRequired, getFarthestViewportElement, getFirstElementChild, getLastElementChild, getNearestViewportElement, getNextElementSibling, getPresentationAttribute, getPreserveAspectRatio, getPreviousElementSibling, getRequiredExtensions, getRequiredFeatures, getScreenCTM, getSvgStyle, getSystemLanguage, getTransformToElement, getViewBox, getXmllang, getXmlspace, getZoomAndPan, hasExtension, querySelector, querySelectorAll, removeEventListener, removeEventListener, setXmllang, setXmlspace, setZoomAndPan
at, at, intAt, intAt, length, numberAt, numberAt, setAt, setAt, setAt, setAt, setAt, setAt
cast, createArray, createArray, createFunction, createObject, equals, hashCode, toSource, toString
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
addEventListener, addEventListener, dispatchEvent, removeEventListener, removeEventListener
intAt, length
numberAt
public final JsFileError getError()
FileReader
getError
in interface FileReader
public final EventListener getOnabort()
FileReader
getOnabort
in interface FileReader
public final void setOnabort(EventListener listener)
setOnabort
in interface FileReader
public final EventListener getOnerror()
FileReader
getOnerror
in interface FileReader
public final void setOnerror(EventListener listener)
setOnerror
in interface FileReader
public final EventListener getOnload()
FileReader
getOnload
in interface FileReader
public final void setOnload(EventListener listener)
setOnload
in interface FileReader
public final EventListener getOnloadend()
FileReader
onload
or onerror
.getOnloadend
in interface FileReader
public final void setOnloadend(EventListener listener)
setOnloadend
in interface FileReader
public final EventListener getOnloadstart()
FileReader
getOnloadstart
in interface FileReader
public final void setOnloadstart(EventListener listener)
setOnloadstart
in interface FileReader
public final EventListener getOnprogress()
FileReader
getOnprogress
in interface FileReader
public final void setOnprogress(EventListener listener)
setOnprogress
in interface FileReader
public final int getReadyState()
FileReader
FileReader
. This will be one of the State constants. Read only.getReadyState
in interface FileReader
public final Object getResult()
FileReader
getResult
in interface FileReader
public final void abort()
FileReader
Aborts the read operation. Upon return, the readyState
will be DONE
.
None.
DOM_FILE_ABORT_ERR
abort()
was called while no read operation was in progress (that is, the state wasn't LOADING
).
abort
in interface FileReader
public final void readAsArrayBuffer(Blob blob)
FileReader
Starts reading the contents of the specified Blob
or File
. When the read operation is finished, the readyState
will become DONE
, and the onloadend
callback, if any, will be called. At that time, the result
attribute contains an ArrayBuffer
representing the file's data.
blob
Blob
or File
to read into the ArrayBuffer
.readAsArrayBuffer
in interface FileReader
public final void readAsBinaryString(Blob blob)
FileReader
Starts reading the contents of the specified Blob
, which may be a File
. When the read operation is finished, the readyState
will become DONE
, and the onloadend
callback, if any, will be called. At that time, the result
attribute contains the raw binary data from the file.
readAsBinaryString
in interface FileReader
public final void readAsDataURL(Blob blob)
FileReader
Starts reading the contents of the specified Blob
or File
. When the read operation is finished, the readyState
will become DONE
, and the onloadend
callback, if any, will be called. At that time, the result
attribute contains a data:
URL representing the file's data.
This method is useful, for example, to get a preview of an image before uploading it:
<!doctype html> <html> <head> <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" /> <title>Image preview example</title> <script type="text/javascript"> oFReader = new FileReader(), rFilter = /^(image\/bmp|image\/cis-cod|image\/gif|image\/ief|image\/jpeg|image\/jpeg|image\/jpeg|image\/pipeg|image\/png|image\/svg\+xml|image\/tiff|image\/x-cmu-raster|image\/x-cmx|image\/x-icon|image\/x-portable-anymap|image\/x-portable-bitmap|image\/x-portable-graymap|image\/x-portable-pixmap|image\/x-rgb|image\/x-xbitmap|image\/x-xpixmap|image\/x-xwindowdump)$/i; oFReader.onload = function (oFREvent) { document.getElementById("uploadPreview").src = oFREvent.target.result; }; function loadImageFile() { if (document.getElementById("uploadImage").files.length === 0) { return; } var oFile = document.getElementById("uploadImage").files[0]; if (!rFilter.test(oFile.type)) { alert("You must select a valid image file!"); return; } oFReader.readAsDataURL(oFile); } </script> </head> <body onload="loadImageFile();"> <form name="uploadForm"> <table> <tbody> <tr> <td><img id="uploadPreview" style="width: 100px; height: 100px;" src="data:image/svg+xml,%3C%3Fxml%20version%3D%221.0%22%3F%3E%0A%3Csvg%20width%3D%22153%22%20height%3D%22153%22%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%3E%0A%20%3Cg%3E%0A%20%20%3Ctitle%3ENo%20image%3C/title%3E%0A%20%20%3Crect%20id%3D%22externRect%22%20height%3D%22150%22%20width%3D%22150%22%20y%3D%221.5%22%20x%3D%221.500024%22%20stroke-width%3D%223%22%20stroke%3D%22%23666666%22%20fill%3D%22%23e1e1e1%22/%3E%0A%20%20%3Ctext%20transform%3D%22matrix%286.66667%2C%200%2C%200%2C%206.66667%2C%20-960.5%2C%20-1099.33%29%22%20xml%3Aspace%3D%22preserve%22%20text-anchor%3D%22middle%22%20font-family%3D%22Fantasy%22%20font-size%3D%2214%22%20id%3D%22questionMark%22%20y%3D%22181.249569%22%20x%3D%22155.549819%22%20stroke-width%3D%220%22%20stroke%3D%22%23666666%22%20fill%3D%22%23000000%22%3E%3F%3C/text%3E%0A%20%3C/g%3E%0A%3C/svg%3E" alt="Image preview" /></td> <td><input id="uploadImage" type="file" name="myPhoto" onchange="loadImageFile();" /></td> </tr> </tbody> </table> <p><input type="submit" value="Send" /></p> </form> </body> </html>
readAsDataURL
in interface FileReader
public final void readAsText(Blob blob)
FileReader
Starts reading the specified blob's contents. When the read operation is finished, the readyState
will become DONE
, and the onloadend
callback, if any, will be called. At that time, the result
attribute contains the contents of the file as a text string.
readAsText
in interface FileReader
public final void readAsText(Blob blob, String encoding)
FileReader
Starts reading the specified blob's contents. When the read operation is finished, the readyState
will become DONE
, and the onloadend
callback, if any, will be called. At that time, the result
attribute contains the contents of the file as a text string.
readAsText
in interface FileReader
Copyright © 2018. All rights reserved.