Hey team,
it seems the evothings client doesn't include the file or fileTransfer cordova plugins.
How would you recommend loading a binary file (from a URL or the device file system) within evothings?
Kind regards,
Rob
Binary file access
Re: Binary file access
I've got round this by using a $.ajax call along with this awesome jQuery extension to support the 'blob' dataType. I can then download binary files from the interwebs (considering CORS of course) and load the resulting binary into an ArrayBuffer...
// jQuery extension to support blob downlaods
$.ajaxTransport("+*", function(options, originalOptions, jqXHR){
if (options.dataType && options.dataType == "blob") {
return {
send: function(headers, completeCallback){
var xhr = new XMLHttpRequest();
var url = options.url || window.location.href;
var type = options.type || "GET";
var dataType = options.dataType;
var data = options.data || null;
var async = options.async || true;
xhr.addEventListener("load", function() {
var response = {};
response[dataType] = xhr.response;
completeCallback(xhr.status, xhr.statusText, response, xhr.getAllResponseHeaders());
});
xhr.open(type, url, async);
for (var header in headers) {
xhr.setRequestHeader(header, headers[header]);
}
xhr.responseType = dataType;
xhr.send(data);
},
abort: function(){
jqXHR.abort();
}
};
}
});
// jQuery extension to support blob downlaods
$.ajaxTransport("+*", function(options, originalOptions, jqXHR){
if (options.dataType && options.dataType == "blob") {
return {
send: function(headers, completeCallback){
var xhr = new XMLHttpRequest();
var url = options.url || window.location.href;
var type = options.type || "GET";
var dataType = options.dataType;
var data = options.data || null;
var async = options.async || true;
xhr.addEventListener("load", function() {
var response = {};
response[dataType] = xhr.response;
completeCallback(xhr.status, xhr.statusText, response, xhr.getAllResponseHeaders());
});
xhr.open(type, url, async);
for (var header in headers) {
xhr.setRequestHeader(header, headers[header]);
}
xhr.responseType = dataType;
xhr.send(data);
},
abort: function(){
jqXHR.abort();
}
};
}
});
Return to “Questions and answers”
Who is online
Users browsing this forum: No registered users and 52 guests