Why my image is not displaying in Ionic 4? - ionic-framework

I want to show an imagen taken with the camera and it's saved in file:///storage/emulated/0/Android/data/myapp.example/cache/1569223935056.jpg
getImage() {
this.data = localStorage.getItem("photoTakenPath")
var filename = this.data.substring(this.data.lastIndexOf('/') + 1);
var path = this.data.substring(0, this.data.lastIndexOf('/') + 1);
this.file.readAsDataURL(path, filename).then(res => {
this.cop = res;
});
console.log(this.cop)
}
And in my HTML
<ion-thumbnail slot="start">
<img [src]="cop" alt="Image" />
</ion-thumbnail>
But when I saw this:
what is displayed

Related

how to preview image before upload in ionic 3?

i am trying to upload and preview image using jquery. But getting this
Error
Property 'result' does not exist on type 'EventTarget'.
reader.onload = function (e) {
$('#blah').attr('src', e.target.result);
}
page.ts
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#blah').attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
$('#file').on('change', function () {
readURL(this);
});
page.html
<label for="file" class="lbl"><i class="fa fa-plus-circle"></i> Add Attachment</label>
<input type="file" id="file" style="visibility: hidden">
<img src="#" id="blah">
what will be the solution?? i think this code is correct but just the problem is 'result' property. Thanks in advance
Some time ago, I used the following code to preview an image in Ionic.
In HTML:
<input type="file" value="" (change)="fileChange($event)">
<img *ngIf="img1" [src]="img1"/>
In JavaScript:
fileChange(event) {
if (event.target.files && event.target.files[0]) {
let reader = new FileReader();
reader.onload = (event:any) => {
this.img1 = event.target.result;
}
reader.readAsDataURL(event.target.files[0]); // to trigger onload
}
let fileList: FileList = event.target.files;
let file: File = fileList[0];
console.log(file);
}
Improvements are welcome
for ionic 4
In html
<img class="logo" src="{{img_new}}" *ngIf="img_new!=''"/>
<input type="file" name="image" accept="image/*" (change)="changeListener($event)">
In ts
changeListener($event): void {
this.file = $event.target.files[0];
console.log(this.file);
let reader = new FileReader();
reader.onload = ($event:any) => {
this.img_new = $event.target.result;
}
reader.readAsDataURL($event.target.files[0]);
}

When applying lockSwipes, I cannot scroll image in X-axis

I am developing an app using ionic v1.
I placed ion-slide-page in ion-slides and ion-scroll in ion-slide-page as shown below. This ion-scroll contains an image.
What I want to do is to keep the slide from moving left and right when the image is enlarged. (Like Facebook)
If I enlarge the image, I cannot scroll the image in X-axis.
Template:
<ion-slides options="options" slider="data.slider">
<ion-slide-page ng-repeat="image in post.imgs">
<ion-scroll
direction="xy"
scrollbar-x="false" scrollbar-y="false"
zooming="true" min-zoom="1" max_zoom="3"
overflow-scroll="false" locking="false" has-bouncing="true"
style="width: 100%; height: 100%" class="vertical-center"
delegate-handle="scrollHandle{{$index}}"
on-release="updateSlideStatus()">
<image style="width: 100%; height: 100%" ng-src="{{image}}"></image>
</ion-scroll>
</ion-slide-page>
</ion-slides>
Contorller:
$scope.$on("$ionicSlides.sliderInitialized", function(event, data){
console.log('ionic slides initialized');
$scope.slider = data.slider;
$scope.activeIndex = 0;
$scope.isSwipeLocked = false;
});
$scope.$on("$ionicSlides.slideChangeStart", function(event, data){
console.log('Slide change is beginning');
});
$scope.$on("$ionicSlides.slideChangeEnd", function(event, data) {
console.log('ionic slides change end');
$scope.activeIndex = data.slider.activeIndex;
$scope.previousIndex = data.slider.previousIndex;
});
$scope.updateSlideStatus = function() {
var zoom = $ionicScrollDelegate.$getByHandle('scrollHandle' + $scope.activeIndex).getScrollPosition().zoom;
if (zoom === 1) {
if ($scope.isSwipeLocked == true) {
$scope.slider.unlockSwipes();
$scope.isSwipeLocked = false;
}
} else {
if ($scope.isSwipeLocked == false) {
$scope.slider.lockSwipes();
$scope.isSwipeLocked = true;
}
}
};
Is there any idea?

Vimeo drop uploader to click uploader

im using vimeo drop uploader on my site. i got the uploder from
https://github.com/websemantics/vimeo-upload
its working well when i drop the image. but i dont know how to on click to open uploder window..
the uploder dont have the file input its only have the div
this is html
<div class="progress">
<div id="progress" class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="46" aria-valuemin="0" aria-valuemax="100" style="width: 0%">0%
</div>
</div>
<div id="drop_zone">Drop files here</div>
and they use this script
<script>
function handleFileSelect(evt) {
evt.stopPropagation();
evt.preventDefault();
var files = evt.dataTransfer.files; // FileList object.
var accessToken = document.getElementById("accessToken").value;
var upgrade_to_1080 = document.getElementById("upgrade_to_1080").checked;
// Set Video Data
var videoName = document.getElementById("videoName").value;
var videoDescription = document.getElementById("videoDescription").value;
// Clear the results div
var node = document.getElementById('results');
while (node.hasChildNodes()) node.removeChild(node.firstChild);
// Rest the progress bar
updateProgress(0);
var uploader = new MediaUploader({
file: files[0],
token: accessToken,
upgrade_to_1080: upgrade_to_1080,
videoData: {
name: (videoName > '') ? videoName : 'Default name',
description: (videoDescription > '') ? videoDescription : 'Default description'
},
onError: function(data) {
var errorResponse = JSON.parse(data);
message = errorResponse.error;
var element = document.createElement("div");
element.setAttribute('class', "alert alert-danger");
element.appendChild(document.createTextNode(message));
document.getElementById('results1').appendChild(element);
},
onProgress: function(data) {
updateProgress(data.loaded / data.total);
},
onComplete: function(videoId) {
var url = "https://vimeo.com/"+videoId;
document.getElementById("video").value = url;
//var a = document.createElement('a');
// a.appendChild(document.createTextNode(url));
// a.setAttribute('href',url);
//
// var element = document.createElement("div");
// element.setAttribute('class', "alert alert-success");
// element.appendChild(a);
//
// document.getElementById('results').appendChild(element);
}
});
uploader.upload();
}
/**
* Dragover handler to set the drop effect.
*/
function handleDragOver(evt) {
evt.stopPropagation();
evt.preventDefault();
evt.dataTransfer.dropEffect = 'copy';
}
/**
* Wire up drag & drop listeners once page loads
*/
document.addEventListener('DOMContentLoaded', function () {
var dropZone = document.getElementById('drop_zone');
dropZone.addEventListener('dragover', handleDragOver, false);
dropZone.addEventListener('drop', handleFileSelect, false);
});
var elem = document.getElementById('drop_zone');
if(elem && document.createEvent) {
var evt = document.createEvent("MouseEvents");
evt.initEvent("click", true, false);
elem.dispatchEvent(evt);
}
/**
* Updat progress bar.
*/
function updateProgress(progress) {
progress = Math.floor(progress * 100);
var element = document.getElementById('progress');
element.setAttribute('style', 'width:'+progress+'%');
element.innerHTML = progress+'%';
}
progress
</script>
Can you help me on this how to i upload an video on click..
Demo https://github.com/googledrive/cors-upload-sample
Thanks

Loading Image from JSON file

I'm trying to load an image from a JSON file into my ionic application.
I can load messages/strings from the JSON file but can't get images to work.
I've created a codepen:
http://codepen.io/beefman/pen/aOpKgL?embed-id=15603
HTML:
<img class="full-image" ng-src="{{item.source}}">
Javscript:
.controller('announcementCtrl', function($scope, $http) {
$scope.data = [];
$scope.infiniteLimit = 1;
$scope.doRefresh = function() {
$http.get('')
.success(function(data) {
$scope.data = data;
$scope.$broadcast('scroll.refreshComplete');
})
.error(function() {
$scope.data = [];
$scope.$broadcast('scroll.refreshComplete');
});
}
Try ng-src=... instead of src=... in the image tag since it's an angular directive.

Error loading MacroEngine script (file: LawyerProfileView.cshtml)

Working on site i been handed and suddnely a couple of macros have started playing up. Macro was working fine now suddenly this error showed up can anyone help here is the code.
#using umbraco.MacroEngines
#inherits umbraco.MacroEngines.DynamicNodeContext
#functions{
public void SetPageTitle(string title)
{
var page = HttpContext.Current.Handler as Page;
if (page != null){
page.Title = title;
}
}
public DynamicNode Homepage
{
get {
var homepage = Model;
while(homepage.NodeTypeAlias != "Homepage"){
homepage = homepage.Parent;
}
return homepage;
}
}
public HtmlString GetSocialMediaLink(string network, string url, string name)
{
var socialMediaRepo = Library.NodeById(-1).DescendantsOrSelf("SocialMediaNetworkRepository").First();
var socialNetworks = new List<DynamicNode>();
if (socialMediaRepo != null)
{
foreach (var child in socialMediaRepo.Children)
{
if(child.NodeTypeAlias.ToLower().Equals(network.ToLower())){
var icon = child.HasValue("CssClass") ? String.Format("<i class=\"{0}\"></i>", child.CssClass) : String.Format("<img src=\"/imagegen.ashx?altimage=/images/assets/clear.gif&image={0}\" alt=\"{1}\"/>", child.Icon, child.Name);
return new HtmlString(String.Format("<a target=\"_blank\" rel=\"no-follow\" href=\"{0}\" title=\"{3} on {1}\">{2}</a>", url, child.Name, icon, name) );
}
socialNetworks.Add(child);
}
}
return new HtmlString("");
}
}
#{
if (String.IsNullOrEmpty(Request["name"])){
return;
}
var profileId = Request["name"].Replace("-", " ").Replace("/", "");
var lawyersRepository = Library.NodeById(1316);
var isIntranet = Homepage.Name.IndexOf("intranet", StringComparison.OrdinalIgnoreCase) > -1;
var nodes = isIntranet ? lawyersRepository.Children.Where("Name.ToLower() = \"" + profileId.ToLower() + "\"") : lawyersRepository.Children.Where("!ProfileIsPrivate && Name.ToLower() = \"" + profileId.ToLower() + "\"");
if(!nodes.Any()){
return;
}
var node = nodes.First();
if (node == null || node.NodeTypeAlias != "LawyerRepositoryItem"){
return;
}
if (node.ProfileIsPrivate && !isIntranet){
return;
}
PageData["PageTitle"] = Model.Name + " - " + node.Name;
SetPageTitle(Model.Name + " - " + node.Name);
var hasContactInfo = (!String.IsNullOrEmpty(node.TelephoneNumber) || !String.IsNullOrEmpty(node.EmailAddress) || !String.IsNullOrEmpty(node.OfficeLocation));
<div class="profile">
<div class="row">
<div class="span4 profile-content">
<h1>#node.Name</h1>
<h3>#node.JobTitle</h3>
#Html.Raw(node.Biography.ToString())
</div>
<div class="span2">
<div class="profile-picture">
#{
if (!node.HasValue("ProfilePictureSquare")){
<img src="/imagegen.ashx?altimage=/images/assets/clear.gif&image=#Library.MediaById(node.ProfilePicture).umbracoFile" alt="#node.Name" />
}
else{
<img src="/imagegen.ashx?altimage=/images/assets/clear.gif&image=#Library.MediaById(node.ProfilePictureSquare).umbracoFile" alt="#node.Name" />
}
}
</div>
<div class="profile-quote">
<!--Tesimonial-->
#RenderPage("~/macroScripts/Widgets/Widget_RandomTestimonial.cshtml", #node.Id.ToString())
</div>
</div>
#if (hasContactInfo)
{
<div class="contact-information">
<div class="pull-left contact-details">
<h4>#Dictionary.ContactInformationHeading</h4>
<dl class="">
#{
if (node.HasValue("TelephoneNumber"))
{
<dd><strong>#Dictionary.Label_TelephoneShort:</strong> #node.TelephoneNumber</dd>
}
if (node.HasValue("EmailAddress"))
{
<dd><strong>#Dictionary.Label_EmailShort:</strong> #node.EmailAddress</dd>
}
if (node.HasValue("OfficeLocation"))
{
var officeNode = Library.NodeById(node.OfficeLocation);
<dd><strong>#Dictionary.Label_Office:</strong> #officeNode.Name</dd>
}
}
</dl>
</div>
<div class="pull-left contact-vcard">
<h4>
<i class="t-icon-vcard"></i> <span>#Dictionary.DownloadVCard</span></h4>
</div>
</div>
}
#{
var hasSocialMediaUrls = node.HasValue("FacebookUrl") || node.HasValue("TwitterUrl") || node.HasValue("LinkedInUrl") || node.HasValue("YouTubeUrl") || node.HasValue("BlogUrl");
if (hasSocialMediaUrls)
{
<div class="profile-social-links social-links">
<ul class="unstyled">
<li><strong>#Dictionary.Connect</strong></li>
#if (node.HasValue("FacebookUrl"))
{
<li>#GetSocialMediaLink("facebook", node.FacebookUrl, node.Name)</li>
}
#if (node.HasValue("TwitterUrl"))
{
<li>#GetSocialMediaLink("twitter", node.TwitterUrl, node.Name)</li>
}
#if (node.HasValue("LinkedInUrl"))
{
<li>#GetSocialMediaLink("linkedin", node.LinkedInUrl, node.Name)</li>
}
#if (node.HasValue("YouTubeUrl"))
{
<li>#GetSocialMediaLink("youtube", node.YouTubeUrl, node.Name)</li>
}
#if (node.HasValue("BlogUrl"))
{
<li>#GetSocialMediaLink("blogger", node.BlogUrl, node.Name)</li>
}
</ul>
</div>
}
}
</div>
<div class="gold-bar">
#Dictionary.SubmitTestimonialText
</div>
</div>
}
i have tried loading from a backup file but the problem persists.
You will need to find out why you got this error.
If you are running in a macro AND you are in WebForms mode, you can add ?umbDebugShowTrace=true (or ?umbDebug=true) at the url. (first check if the umbracoDebugMode appsetting in the web.config is true).
If this is not working, check the App_Data/Logs/ folder for any log files. You should see the complete error there. If you have an older version, check also the umbracoLog database table.
Best thing to do is to look in /App_Data/Logs/UmbracoTraceLog.txt which will show you the logs recorded for today.
This will reveal the root of the error and full stack trace.