Phonegap - HTML does not display image from storage - html

I'm using FileTransfer plugin to download an image from a remote server.
The image is stored in "storage/emulated/0/" - using the following code:
function downloadFile(fileDownloadName){
//console.log('downloadFile');
window.requestFileSystem(
LocalFileSystem.PERSISTENT,
0,
function(fileSystem){
//console.log('onRequestFileSystemSuccess');
fileSystem.root.getFile(
'dummy.html',
{create: true, exclusive: false},
function(fileEntry){
//console.log('onGetFileSuccess!');
var path = fileEntry.toURI().replace('dummy.html', '');
var fileTransfer = new FileTransfer();
fileEntry.remove();
fileTransfer.download(
'https://www.myserver.com/imagens/' + fileDownloadName,
path + fileDownloadName,
function(file) {
//console.log('download complete: ' + file.toURI());
return path + fileDownloadName;
},
function(error) {
console.log('download error source ' + error.source);
console.log('download error target ' + error.target);
console.log('upload error code: ' + error.code);
}
);
},
fail
);
},
fail
);
}
So, I'm pointing the path + fileDownloadName to SRC of my image, but the image does not appear.
var location = path + fileDownloadName;
window.resolveLocalFileSystemURL(location, function(oFile) {
oFile.file(function(readyFile) {
var reader= new FileReader();
reader.onloadend= function(evt) {
$(".circle-perfil").css('background-image', 'url(' + evt.target.result + ')');
};
reader.readAsDataURL(readyFile);
});
Is there something wrong I'm doing? Should I have to store the image in another folder? If yes, how to do it?

If you are using img tag then set its image as:
$(".circle-perfil").css('background', 'url(' + evt.target.result + ')');
or
$(".circle-perfil").css('content', 'url(' + evt.target.result + ')');
In case of div or span
$(".circle-perfil").css('background-image', 'url(' + evt.target.result + ')');
I had set it like:
var image = document.getElementById('cameraPic');
image.src = 'path/of/image file';

Related

How to correctly submit POST positioning request via HERE API from a local environment?

I develop locally on Windows 10 using XAMPP stack.
http://localhost:8003/myFolder/
This is my code:
Code snippet: URL without CORS mechanism
I get the following error:
POST https://pos.ls.hereapi.com/positioning/v1/locate?apiKey=Lxj-xbibfpSHLMw1U...blabla
net::ERR_ABORTED 400 (Bad Request)
Code snippet: URL with CORS mechanism
I get the following error:
POST http://host/path?CORSH=%7B%22Content-Type%22%3A%22application%2Fvnd.here.layerObjectList%2Bjson%3B%20charset%3Dutf-8%22%2C%22Accept%22%3A%22application%2Fjson%3B%20charset%3DUTF-8%22%2C%22GroupId%22%3A%22FGx1AWaAzKOo0imNkLmf%22%2C%22AuthServiceId%22%3A%22here_app%22%2C%22Auth-Identifier%22%3A%22Ykv6MmZ03OJtiFD4R7Ht%22%2C%22Auth-Secret%22%3A%22AXqUNisVW46XJs9_pxuzOzneKlYPrY5X_blablabla
net::ERR_NAME_NOT_RESOLVED
I have the same problem:
url = 'https://geocode.search.hereapi.com/v1/geocode?q=Eichholz 27 ,+ 20459 ,+ Hamburg ,+ D&apiKey=yYoMr6vEReqc_sI0HAPMqIu3fYJdGcRsBR5t-xxxxxx' ;
$.ajax({
crossDomain: true,
type : 'get',
headers: { 'Access-Control-Allow-Origin': '*' },
url : url ,
contentType: "application/json; charset=utf-8",
dataType : 'json',
jsonCallback : 'getJson',
async : false,
success : function(data) {
$.each(data, function(counter, daten) {
alert('return -- ' + daten.titel) ;
});
},
error : function(data, req, status, err) {
alert('something went wrong !!! getLatLng(url)');
// console.log('something went wrong', status, err);
}
}); // ajax end
Quellübergreifende (Cross-Origin) Anfrage blockiert: Die Gleiche-Quelle-Regel verbietet das Lesen der externen Ressource auf https://geocode.search.hereapi.com/v1/geocode?q=Winterfeldtstrasse%2079,+%2010781%20,+%20Berlin%20,+%20GERMANY&apiKey=yYoMr6vEReqc_sI0HAPMqIu3fYJdGcRsBR5t-xxxxx. (Grund: CORS-Anschlag schlug fehl)
in principal, AJAX did not support external URL.
If you must call aURL Like
url = 'https://geocode.search.hereapi.com/v1/geocode?q=Eichholz 27 ,+ 20459 ,+ Hamburg ,+ D&apiKey=yYoMr6vEReqc_sI0HAPMqIu3fYJdGcRsBR5t-xxxxxx' ;
You must do it with $.getJSON .
Like:
function getLatLng(url, location_id) {
$.getJSON(url, function(data) {
$.each(data, function(counter, daten) {
// alert(url);
JSON.stringify(daten);
// alert('return -- ' + counter + '-- ' + daten.title ) ;
function print_r(printthis, returnoutput) {
var output = '';
if ($.isArray(printthis) || typeof (printthis) == 'object') {
for ( var i in printthis) {
output += i + ' : ' + print_r(printthis[i], true)
+ '\n';
// alert('for - ' + printthis[i]);
}
} else {
output += printthis;
// alert('else - ' + printthis + '--' + printthis[i]);
}
if (returnoutput && returnoutput == true) {
return output;
} else {
// alert(output);
var nlat = output.indexOf("lat : ", 10);
// alert(nlat);
var lat = output.substring((nlat + 6), ((nlat + 6) + 9));
var nlng = output.indexOf("lng : ", 10);
var lng = output.substring((nlng + 6), ((nlng + 6) + 9));
alert('location_id - ' + location_id + ' lat ' + lat + ' lng ' + lng);
updateAdress(lat, lng, location_id , todo)
}
}
print_r(daten);
// console.dir(daten);
}); }); }

Best way to load/store ndDialog template?

I am using ngDialog to display a modal window with an alert message.
I have the modal window working however the code looks messy.
I am wondering is it possible to replace the raw html template with a link to a html file instead of writing the HTML within the function itself.
$scope.openDialog = function(components) {
$scope.selected = components.component;
ngDialog.open({
template: '<h4>' + 'Alert' + '</h4>' +
'<table class="table">' +
'<tr><th>Type</th><td>' + components.type + '</td></tr>' +
'<tr><th>Component</th><td>' + components.component + '</td></tr>' +
'<tr><th>Created</th><td>' + components.created + '</td></tr>' +
'<tr><th>Alert</th><td>' + components.alert + '</td></tr>'+
'</table>',
plain: true
});
};
Yep, just use templateUrl rather than template.
$scope.openDialog = function(components) {
$scope.selected = components.component;
ngDialog.open({
templateUrl: 'yourfilename.html',
plain: true
});
};

How to use mailto attachment in Angular.js

I want to add attachment path, how to add attachment in mailto.
I have tried like following but that not worked.
$scope.sendMail = function ()
{
$scope.to = "To#gmail.com";
$scope.cc = "CC#gmail.com";
$scope.bcc = "bcc#gmail.com";
$scope.subject = "Confirmation";
var link = "mailto:" + $scope.to
+ "?cc=" + $scope.cc
+ "&bcc=" + $scope.bcc
+ "&subject=" + $scope.subject
+ "&body=" + "Test Body";
+"&attachment="
window.location.href = link;
}

How to parse JSON url of api data and display in div

I want to get the data from Json url api page, how can i get this, please help me in this regards
$(document).ready(function() {
$("#driver").click(function(event){
$.getJSON('http://globalmetals.xignite.com/xGlobalMetals.json/GetLondonFixing?Symbol=XAU&Currency=USD', function(data) {
var json = $.parseJSON(data);
$('#stage').html('<p> Outcome: ' + json.Outcome + '</p>');
$('#stage').append('<p>Message : ' + json.Message+ '</p>');
$('#stage').append('<p> Name: ' + json.Name+ '</p>');
});
});
});
When you use $.getJSON, the data is already parsed for you, it's wrong to call $.parseJSON.
$.getJSON('http://globalmetals.xignite.com/xGlobalMetals.json/GetLondonFixing?Symbol=XAU&Currency=USD', function(json) {
$('#stage').html('<p> Outcome: ' + json.Outcome + '</p>');
$('#stage').append('<p>Message : ' + json.Message+ '</p>');
$('#stage').append('<p> Name: ' + json.Name+ '</p>');
});

How to scale inline SVG

I want to scale inline SVG document in html. I have code like this:
var svg_width = svg.attr('width');
var svg_height = svg.attr('height');
function resize(width, height) {
svg.attr('width', width).attr('height', height);
var group = svg.find('#resize_group');
if (!group.length) {
group = svg.children().not('metadata, defs').wrapAll('<g/>').
parent().attr('id', 'resize_group');
}
var matrix = svg[0].createSVGMatrix();
//var matrix = group[0].getCTM();
matrix.a = width/svg_width;
matrix.d = width/svg_height;
group.attr('transform', matrix.asString());
}
SVGMatrix.prototype.asString = function() {
return 'matrix(' + this.a + ' ' + this.b + ' ' + this.c + ' ' + this.d +
' ' + this.e + ' ' + this.f + ')';
};
NOTE: I need to transform the elements inside svg because otherwise the image is trimmed.
but when I call resize function whole svg disappear. I've save svg to file and open it in Inkscape and it look normal (it's scaled). Why the svg disappear? (I tested on Firefox, Chrome and Opera)
I found quick hack, to replace svg with text of the svg to force redraw.
$.fn.xml = function() {
return (new XMLSerializer()).serializeToString(this[0]);
};
$.fn.SVGRedraw = function() {
return $(this.xml()).replaceAll(this);
};