I'm stuck in the image array where I can patch image array value in my edit form there can I upload other images or push images that array or delete.
I have a product model where I can have a sub-array where I can trigger edit query or patch value.
onSelectFile(event: any) {
if (event.target.files && event.target.files[0]) {
var filesAmount = event.target.files.length;
for (let i = 0; i < filesAmount; i++) {
var reader = new FileReader();
reader.onload = (event: any) => {
console.log("image1",event.target.result);
this.urls.push(event.target.result);
};
reader.readAsDataURL(event.target.files[i]);
}
}
}
<div class="fileupload-wrapper">
<div>
<button class="file-upload-button" type="button" for="custom-fileupload">
<img src="assets/images/icons/file-upload.svg"
alt="file-upload"><span>Upload</span>
<input type="file" accept="image/*;base64," id="file" #file
(change)="onSelectFile($event)" id="custom-fileupload" class="custom-fileupload" multiple />
</button>
</div>
<span class="file-info">
<div *ngFor='let url of urls; let i = index' class="category-wrapper">
<img [src]="sanitizeImageUrl(url)" *ngIf="url" class="categroy-images">
<span (click)="resetCoverValue(i)" class="cross-icon">{{ this.documentName ?
"close" : null }}
<img src="assets/images/icons/blue-cross.svg">
</span>
</div>
</span>
</div>
Related
As part of my application I have the following function in my react class for updating the state:
updateReplies(minorRevision, ParentCommentId) {
const ids = allComments.map(object => {
return object.Id;
});
console.log(ParentCommentId);
const localId = allComments[allComments.length - 1].LocalId + 1;
const itemId = this.state.currentUser.ItemId;
const name = this.state.currentUser.Name;
const newId = Math.max(...ids) + 1;
const comment = this.state.textAreaComment;
const recipients = this.state.selectedValues;
const commentDate = toIsoString(new Date());
const newComment = {
AttachmentId: null, Comment: comment, Commenter: { ItemId: itemId, Name: name },
Id: newId, IsDeleted: false, LocalId: localId, MinorRevision: minorRevision, ParentCommentId: ParentCommentId,
Recipients: recipients, Time: commentDate
};
allComments.push(newComment);
const groupedComments = groupByRevision(allComments);
this.setState({ Comments: groupedComments });
saveReply();
};
This is then past through a couple of functions before coming to the one where I will be passing the parameters through:
export function GetComments(props) {
return (
<React.Fragment>
{props.commentsArray.map((comment, index) => {
const localId = comment.LocalId;
const parentCommentId = comment.ParentCommentId;
const parentLocalId = allComments.filter(obj => obj.Id === parentCommentId);
const recipients = comment.Recipients;
let recipientsArray = [];
let recipientsList;
recipients.forEach(function (arrayItem) {
recipientsArray.push(arrayItem.Name);
recipientsList = recipientsArray.join(', ');
});
const date = new Date(comment.Time);
const formattedDate = date.toLocaleDateString() + " " + ("0" + date.getHours()).slice(-2) + ":" + ("0" + date.getMinutes()).slice(-2);
return (
<div key={localId} className="comment-container">
<div key={comment.Commenter.ItemId} className="commenter">
<span className="id-label">{localId}</span>
{parentCommentId && (
<span className="reply" title={`in reply to ${parentLocalId[0].LocalId}`}>
<a className="reply" href={"#c" + parentLocalId[0].LocalId}>⤵</a> </span>
)}
<span><a id={"c" + localId} name={"c" + localId}>{comment.Commenter.Name}</a></span>
<div className="comment-actions-container">
<button type="button" className="btn-reply" data-value={comment.Id} title="Reply to comment" data-toggle="modal" data-target="#dlg-new-reply">💬</button>
</div>
</div>
<div className="modal fade" id="dlg-new-reply" tabIndex="-1" role="dialog" aria-labelledby="modalLabelLarge" aria-hidden="true">
<div className="modal-dialog modal-lg">
<div className="modal-content">
<div className="modal-header">
<h4 className="modal-title" id="modalLabelLarge">Reply</h4>
</div>
<div className="modal-body">
<span id="current-comment-display">{"Currently selected: " + comment.Id}</span>
<div className="address-list-container">
<Select placeholder="Send to ..." id="cboAddressees" isMulti name="addressees" onChange={props.getSelected} options={options} />
</div>
<textarea id="txtReply" onChange={props.getTextComment} name="reply"></textarea>
</div>
<div className="modal-footer">
<button type="button" className="btn" data-dismiss="modal" aria-label="Cancel">
<span aria-hidden="true">Cancel</span>
</button>
<button id="save-reply" type="button" onClick={() => props.setChange(comment.MinorRevision, comment.Id)} className="btn">Save</button>
</div>
</div>
</div>
</div>
<div id={"recipients-" + comment.Id} className="recipients">{recipientsList}</div>
<div className="comment">{comment.Comment}</div>
<div className="comment-footer">{formattedDate}</div>
<GetReplies Id={comment.Id} />
</div>
);
})}
</React.Fragment>
);
}
Now for here, for each comment I am rendering these elements and this works fine however, when we get to this part:
<button id="save-reply" type="button" onClick={() => props.setChange(comment.MinorRevision, comment.Id)} className="btn">Save</button>
I am having some issues, I am not getting any errors but the wrong values are getting passed through, instead of the MinorRevision and Id of that individual comment, it is just passing through the values of the very last comment if that makes sense.
What I am finding confusing is that for the rest of it, I am not having that issue like for example in here:
<button type="button" className="btn-reply" data-value={comment.Id} title="Reply to comment" data-toggle="modal" data-target="#dlg-new-reply">💬</button>
I am getting the correct Id, so at the moment the highest Id value is 158 and MinorRevision value is 2 and no matter which element I am clicking on, that is what is passed through props.SetChange and I have no idea why that would be the case
Edit -
So the problem seems to be with using bootstrap modal and I have no idea why this would be happening. When the modal is opened, it will show the very last of the comment objects but everything underneath the modal i.e:
<div className="comment">{comment.Comment}</div>
will show the correct values, so it is something to do with the modal but I'm just not sure what
How can I stop getting 401 errors when I upload an image?
API
public function upload_office_logo(Request $request, $header_image)
{
$header_image = $request['header_image'];
$profileImageSaveAsName = time().".".$header_image->getClientOriginalExtension();
Storage::put('public/header_image/'.$profileImageSaveAsName,
file_get_contents($header_image));
return $header_image;
}
Angular UI
saveButton()
{
let logo = this.officeModel.header_image;
var filename = logo.split("\\", 3);
console.log(filename[2]);
this.officeModel.login_pw = "password123";
this.officeService.addOfficeLogo(filename[2]).subscribe(data => {
});
this.officeModel.header_image = filename[2];
this.officeService.addOffice(this.officeModel).subscribe(data => {
this.toastr.success('Added Successfuly', 'Success');
this.router.navigate(['/dashboard-manage/office']);
});
}
HTML
<div class="flex-input-grp">
<div class="required-label">{{ setLabel("Office Logo") }}</div>
<span class="label label-danger">{{ setLabel("Required") }}</span>
<div class="inp-container">
<input type="file" #fileUpload id="header_image" name="header_image" accept="image/*"
class="inp" [(ngModel)]="officeModel.header_image" [ngModelOptions]="{standalone: true}">
</div>
</div>
Hi Here I have to upload single/multiple files in angular js . I have used the below link for uploading files. In this they have uploaded the images but instead I have to upload pdf and image.
<div class="container">
<div ng-controller="MyCtrl" class="row">
<button class="btn btn-primary pull-right" ng-hide="images.length == 0" ng-click="clearAll()">Clear All</button>
<h3 ng-bind="name"></h3>
<input type="file" ng-click="$event = $event" ng-model="display" multiple onchange="angular.element(this).scope().upload(event)" accept="image/png, image/jpeg, image/gif" />
<div class="row">
<div class="col-md-12"> <span ng-repeat='img in images'> <a href="#" ng-click="setImage($index)">
<img ng-src="{{img}}"
alt="Generic placeholder thumbnail" style="max-height:100px;" class="thumbnail"/>
</a>
</span>
</div>
</div>
<img ng-src="{{display}}" ng-hide="!display" />
<h4>You have upload {{images.length}} images this session.
</h4>
</div>
</div>
var myApp = angular.module('myApp', []);
myApp.controller('MyCtrl', function ($scope) {
$scope.name = "Select Files to Upload";
$scope.images = [];
$scope.display = $scope.images[$scope.images.length - 1];
$scope.setImage = function (ix) {
$scope.display = $scope.images[ix];
}
$scope.clearAll = function () {
$scope.display = '';
$scope.images = [];
}
$scope.upload = function (obj) {
var elem = obj.target || obj.srcElement;
for (i = 0; i < elem.files.length; i++) {
var file = elem.files[i];
var reader = new FileReader();
reader.onload = function (e) {
$scope.images.push(e.target.result);
$scope.display = e.target.result;
$scope.$apply();
}
reader.readAsDataURL(file);
}
}
})
Thanks in advance.
In this I can able to see the selected images on clicking choose file. But, if it is PDF format i cant able to see the image. Pls provide the solution for PDF.
You can use javascript and PDF.JS.
Example like this:
How to Convert PDF to Image (JPEG / PNG) with Javascript using PDF.JS
How to print in drop-down list in jxs? Actually I'm having drop-down list and by this code i'm getting all the data in one single row while clicking on it but I want it in list. Can anyone help me out for this?
My code:
comboClick () {
var apiBaseUrl = "http://api.eventsacross-stage.railsfactory.com/api/";
var input = this.state.search_event;
let self = this;
let location = [];
let cityArray = [];
axios.get(apiBaseUrl+'v1/events/?on_dashboard=false'+input)
.then(function (response) {
let events = response.data.events;
for(var i = 0; i < response.data.events_count; i++) {
var obj = response.data.events[i];
location.push(obj.locations[0].city);
}
let cityUnique = _.uniq(location, 'city');
cityArray.push(cityUnique);
self.setState({cityArray: cityArray});
})
.catch(function (error) {
console.log(error);
});console.log("cityArray",cityArray);
}
jsx part:
render() {
var cityFilter = [this.state.cityArray ? this.state.cityArray[0] : null];
{console.log("cityFilter",cityFilter)}
return (...
<div className="dropdown text-center">
<button
className="btn btn-default dropdown-toggle"
type="button"
data-toggle="dropdown"
style={{width: "50%"}}
onClick={this.comboClick.bind(this)}>
Place
<span className="caret"></span>
</button>
<ul className="dropdown-menu">
{cityFilter.map(function(city, index){
return <li className="text-center" key={ index }>{city}</li>;
})}
</ul>
</div>
...}
I need a redux-form render field where I can upload image with a preview thumbnail and get base-64 value.
Form
<form className="AddProductForm" onSubmit={handleSubmit(this.addProduct.bind(this))}>
<div className="form-group clearfix">
<img className="addProductImg pull-left" src="" height="200" alt="Image preview..." />
<input className="pull-right addProductImgBtn" type="file" onChange={previewFile} />
</div>
<div className="form-group">
<Field name="name" component={this.renderField} type="text" placeholder="Product name" />
</div>
<Button onClick={close}>Cancel</Button>
<button className='btn btn-primary addProductSave' type="submit" value="CONFIRM">Save</button>
</form>
File upload
function previewFile() {
var preview = document.querySelector('.addProductImg');
var file = document.querySelector('input[type=file]').files[0];
var reader = new FileReader();
reader.onloadend = function () {
preview.src = reader.result;
let upImage = preview.src;
this.imageUrl = preview.src; // Base-64 value
}
if (file) {
reader.readAsDataURL(file);
} else {
preview.src = "";
}
}
I can get the base-64 value here, but I am unable to add this value into the existing field set.
Submit function
addProduct = (values) => {
console.log("Field values", values);
console.log("image base64 value", this.imageUrl);
}
Here inside addProduct function I want to get the image value with base64 encoding.