MozNFCPeer.sendFile()
The sendFile()
method of the MozNFCPeer
interface sends a file — over a non-NFC data channel — to another device.
Note: sendFile()
currently uses Bluetooth for data transport.
Syntax
JavaScript
Copy Code
<span id="idl-def-IDBIndex" class="idlInterface"><span id="idl-def-MediaRecorder" class="idlInterface"><span class="idlMethod">var req = nfcPeer.sendFile(flieblob);</span></span></span>
Example
js;highlight:[6]
Copy Code
var nfcdom = window.navigator.mozNfc; nfcdom.onpeerready = function(event) { var nfcPeer = nfcdom.getNFCPeer(event.detail); var blob = ... // construct a 'blob' that is of type 'file'. // This 'blob' will be passed onto / handover to Bluetooth interface for the actual file transfer. (Wifi handover is not yet supported) var req = nfcPeer.sendFile(blob); req.onsuccess = function(e) { console.log("Successfully sent file"); }; req.onerror = function(e) { console.log("Send file failed!"); }; };
Parameters
The Blob
file reference to be transferred.
Returns
A DOMRequest
object.
Errors
Error("Unable to create NFCPeer object, Reason: Bad SessionToken")
Specifications
The NFC implementation in Gecko follows the NFC Forum specifications.
Browser compatibility
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|
Basic support |
No support |
No support | No support | No support | No support |
Feature | Android | Firefox Mobile (Gecko) | Firefox OS (Gecko) | IE Phone | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | No support | No support | 2.0 moz [1] | No support | No support | No support |
[1] Available in privileged apps as of Firefox OS 2.2; certified-only before that.
See also
- Using the NFC API
- Using the NFC emulator
- Introduction to NFC (fairly long reference doc, featuring general NFC terms, and some Nokia platform specifics.)
License
© 2016 Mozilla Contributors
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-us/docs/web/api/moznfcpeer/sendfile