|
Finally implemented by using the FileStreamResult as well maybe some people would be needed this, here is my API code and then I made call to the post method using axios, so here is my React code. In the axios call responseType becomes arraybuffer and the in the blob declaration it becomes the application/octet-stream type, Hence it completes everything, as I have imported the file-saver, I could able to use saveAs method of it. Finally after many efforts and hearing the screaming from PM, yes it is achieved - but that's the life of any Software Programmer.
Here is Web Api code C#:
[EnableCors("AnotherPolicy")]
[HttpPost]
public FileStreamResult Post([FromForm] string communityName, [FromForm] string files)
{
var removedInvalidCharsFromFileName = removeInvalidCharsFromFileName(files);
var tFiles = removedInvalidCharsFromFileName.Split(',');
string rootPath = Configuration.GetValue<string>("ROOT_PATH");
string communityPath = rootPath + "\\" + communityName;
MemoryStream zipStream = new MemoryStream();
using (ZipArchive zip = new ZipArchive(zipStream, ZipArchiveMode.Create, true))
{
foreach (string attachment in tFiles)
{
var zipEntry = zip.CreateEntry(attachment);
using (FileStream fileStream = new FileStream(communityPath + "\\" + attachment, FileMode.Open))
{
using (Stream entryStream = zipEntry.Open())
{
fileStream.CopyTo(entryStream);
}
}
}
}
zipStream.Position = 0;
return File(zipStream, "application/octet-stream");
}
Then my client side React code is here:
handleDownload = (e) => {
e.preventDefault();
var formData = new FormData();
formData.append('communityname', this.state.selectedCommunity);
formData.append('files', JSON.stringify(this.state['checkedFiles']));
let url = clientConfiguration['filesApi.local'];
axios({
method: 'post',
responseType: 'arraybuffer',
url: url,
data: formData
})
.then(res => {
let extension = 'zip';
let tempFileName = `${this.state['selectedCommunity']}`
let fileName = `${tempFileName}.${extension}`;
const blob = new Blob([res.data], {
type: 'application/octet-stream'
})
saveAs(blob, fileName)
})
.catch(error => {
console.log(error.message);
});
};
this event is called when button is clicked or form submitted. Thanks for all the support the SO has given - thanks a lot.
|
|
|
|
|
Hi I have stored an Array of strings into a state object, when I am trying to retrieve it as appended string, it is giving me appended objects as below, my code is as below and I am getting the result as below:
handleDownload = (e) => {
e.preventDefault();
var formData = new FormData();
formData.append('communityname', this.state.selectedCommunity);
formData.append('files', this.state['files']);
alert(this.state['files'].join(','));
let url = clientConfiguration['filesApi.local'];
axios({
method: 'post',
url: url,
data: formData
});
}
My Results are coming as below:
[object Object],[object Object],[object Object],[object Object]
Any help would be very much appreciated - thanks in advance
|
|
|
|
|
Looks like the values stored in this.state['files'] aren't what you thought they are.
Try adding console.debug(this.state['files']); to the method, and look at the output in the browser's developer console.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks Richard, it has been resolved, I have to stringify it before posting it into the Api, here is the code that resolved it. Thanks for jumping into help.
handleDownload = (e) => {
e.preventDefault();
var formData = new FormData();
formData.append('communityname', this.state.selectedCommunity);
formData.append('files', JSON.stringify(this.state['checkedFiles']));
let url = clientConfiguration['filesApi.local'];
axios({
method: 'post',
url: url,
data: formData
});
}
in the above code instead of files I am just passing the selected files and posting them, but I have a question, can't json or react post handle if I want to post Array as it is? If it can - I want to understand that as well - but thanks a lot again Richard.
|
|
|
|
|
I have an event like below:
handleDownload(e) {
e.preventDefault();
alert('Hi');
let communityName = this.state['selectedCommunity'];
let files = this.state[files];
fetch(clientConfiguration['filesApi.local'], {
method: 'POST',
headers: new Headers(),
body: JSON.stringify({ communityName: communityName, body: files })
}).then((res) => res.json())
.then((data) => console.log(data))
.catch((err) => console.log(err))
};
I have a button as below:
renderDownloadButton() {
if (this.state.files && this.state.files.filter(i => i.checked).length) {
return (
<button id="download" styles="display: none;" onClick={this.handleDownload} >
Download
</button>
);
}
};
It fires but it is giving following error, any help please - thank you. At
let communityName = this.state['selectedCommunity'];
its giving me the error;
Can not read property state undefined
Any help please?
|
|
|
|
|
state is undefined, it has no value and is not null either.
state is not inside the function, so you have to initialize earlier in code.
Or maybe pass the state into the function, but I can't see how you can pickup the state in the HTML section and not have it valid in the function. Check your renderDownloadButton
Not sure how React works but I would imagine this is required.
onClick={this.handleDownload($event)}
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
Yes it was taking the function as the current object that's how all javascript libraries work, so changing the scope worked for me - thanks a lot.
|
|
|
|
|
Hi mates, I am conditionally setting up the state in my React component, I did it in the following way, it works but please let me know if there is any better approach to do it in React - thanks a lot.
handleDDLCommunityChange = event => {
this.setState(
{
selectedCommunity: event.target.value
});
if (event.target.value == "") {
this.setState(
{
files: null
});
}
else {
fetch(clientConfiguration['filesApi.local'] + '/' + event.target.value)
.then((response) => { return response.json(); })
.then(data => {
this.setState({
files: data.map(file => {
return {
fileName: file,
checked: false
}
})
})
})
.catch(error => {
console.log(error);
debugger;
});
}
};
modified 9-Oct-19 21:09pm.
|
|
|
|
|
Why not this instead? Maybe the target value is null or undefined and not a blank string.
This should check all 3 conditions in TypeScript at least.
if (!event.target.value)
If it was me, I would not inline this, but if it's proven to always work guess it's ok.
fetch(clientConfiguration['filesApi.local'] + '/' + event.target.value)
const fApi = clientConfiguration['filesApi.local'];
if (fApi) {
fetch(fApi + '/' + event.target.value)
Have you considered trying Jet Brains Refactor Ultimate to sharpen your skills?
ReSharper: The Visual Studio Extension for .NET Developers by JetBrains
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
Hello,
I plot a chart based on different datasets.
one datasets has different datapoints (xn,yn)
dataset 1 = (x1,y1) .... dataset 10 (x10,y10)
First question, how to plot those datasets in javascript?
Second question:
I want to add a dropdown menu to select dataset1, dataset2 , dataset3 in the graph.
would be nice if you have a code samples for me which solve my problem.
|
|
|
|
|
After huge research, i am thinking to build with JavaScript - Search engine with Angular/Vue.js/Meteor/React as front-end
Choice of javascript client side storage is below
1) IndexedDB
2) JScene
3) LargeLocalStorage
4) ydn db
5) PouchDB
Couple of Links
https:
https:
http:
https:
Please kindly suggest which one would be best suited...
Basically planning to built a cross platform system which accepts huge files from the user and finally does a full text search...
In this way, the user just needs the browser no installation is required......
In this way, the application will be purely portable irrespective of OS....
This would be absolutely cross platform
Featurs trying to build once the files got indexed by the front-end code/logic
1) Search Box with type-ahead search
2) Combo box to choose the language
3) Number of hits should be while typing. Please type some text in and
you will understand what is number of hits
4) Search keyword should be highlighted in the left with portion of text.
On clicking the text, the entire subject with highlighted search
should shown in the right
nearly 2,000 files are in text format of 600 kB each size.
the files can be anything - log file or any text file....If support other formats also it is well and good
Please kindly advice with suggestions or comments... As this will benefit for many...
I never come across several open source apps which does full text search or have the functionality which does everything in front-end or client-side
Thanks.
|
|
|
|
|
hmm...
I would choose JScene.
Seems to be designed for your concept.
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
But JScene is a proof of concept..It's not a completed product or reliable to be used in production.
We need a validated and proven open source which is active in development, so that we get proper support.
Can you suggest a working and proven library similar like JScene?
|
|
|
|
|
No.
I use Local Storage for storing JWT Auth Tokens and other small stuff such as program options, But have never considered using it for storing a database. The thought simply never occurred to me.
I see it different, because I as a user use my Desktop at work to shop, and my phone at home to purchase or vice versus.
I would not want to write a program in which the data was not available on both my devices.
But:
I am considering on my next shopping application written in a JavaScript framework like Angular to store cart content on the users device in cookies or perhaps Local Storage. To just use a JSON format and store the JSON text as a string. Perhaps a combination of both, in which the cookie says there is cart data and the data is in Local Storage. But this would break my rule unless I read the cookie, and if the user is logged in, I pickup the cart content and write it to their account document in MongoDB. I think EBay is doing this now.
But for you, what your doing is experimental as well and you seem to share the same idea with the JScene developer.
You would have to do a proof of concept in code and try them and see which works better. Just fill your concept with fake data but make sure you can store and retrieve.
[edit]
Not everything you can imagine has already been written and available as open source with support. Most web developers have never even heard of Local Storage, so the pool of choices for this will be very small. Your idea is an extreme concept.
Just my Opinion
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
jquery validation in Drop down..
if i am select the value another same div can't select this value..
and print the alerdy message "this value already selected"
|
|
|
|
|
There is no magic way to do it. You need to write code to do it.
Write code for the change event of the dropdown. Check if it's value is already selected. If so, display a message and reset the dropdown selected value.
Social Media - A platform that makes it easier for the crazies to find each other.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
<pre lang="Javascript"><pre lang="Javascript"> $("#everything").validate({
onsubmit: true,
rules: {
dd1: {
required: {
depends: function(element) {
return $("#dd1").val() == "none";
}
}
},
messages: {
dd1: {
required: "Please select an option from the list, if none are appropriate please select 'Other'",
},
}
});
|
|
|
|
|
Just remove the value from the next select using JQuery
Then if they change the first value, add the value back, or reload the values in the next select
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
I have created a dynamic drop-down list using JavaScript and I want the alert that is triggered on the screen after making the selections to say the wrestling level picked the wrestler name picked and the year in the alert and after that I want the JavaScript code to display an I-frame that contains a table of that wrestler's videos for that year. I somewhat understand the logic of the drop-down list but I don't know how to put the selections that I make on the list display in the alert such as the wrestling level picked the wrestler name picked and the year. Right now all the alert does is displays the final selection which is the year but I want all the selection information to be put into the alert. Secondly after this alert displays I want the JavaScript code to trigger the creation of an I-frame that displays a table with all the wrestler's videos for that year. I know how to create the table and information related with that but I can't seem to figure out the code to create an I-frame. As far as JavaScript goes I'm not very experienced and would be considered a beginner any help would be appreciated. The code I have is below.
<!DOCTYPE html>
<html lang="en-us">
<head>
<title>Test</title>
<script type="text/javascript">
function urlRedirectTo(obj)
{
alert('Here are all the wrestling videos for '+obj);
if('2013-2014' == obj)
var iframe = document.createElement('iframe');
var html = '<body>Foo</body>';
document.body.appendChild(iframe);
iframe.contentWindow.document.open();
iframe.contentWindow.document.write(html);
iframe.contentWindow.document.close();
}
function dynamicdropdown(listindex)
{
document.getElementById("sub_subcategory").length = 0;
document.getElementById("sub_subcategory").options[0]=new Option("Please select Year","");
document.getElementById("subcategory").length = 0;
switch (listindex)
{
case "Elementary" :
document.getElementById("subcategory").options[0]=new Option("Please select Wrestler","");
document.getElementById("subcategory").options[1]=new Option("Wordpress","Wordpress");
document.getElementById("subcategory").options[2]=new Option("Magento","Magento");
break;
case "Junior High" :
document.getElementById("subcategory").options[0]=new Option("Please select Wrestler","");
document.getElementById("subcategory").options[1]=new Option("Strauts","Strauts");
document.getElementById("subcategory").options[2]=new Option("Hibernate","Hibernate");
break;
case "Junior Varsity" :
document.getElementById("subcategory").options[0]=new Option("Please select Wrestler","");
document.getElementById("subcategory").options[1]=new Option("Prototype","Prototype");
document.getElementById("subcategory").options[2]=new Option("jQuery","jQuery");
break;
case "Varsity" :
document.getElementById("subcategory").options[0]=new Option("Please select Wrestler","");
document.getElementById("subcategory").options[1]=new Option("Marc Hendricks","Marc Hendricks");
break;
default:
document.getElementById("subcategory").options[0]=new Option("Please select Wrestler","");
break;
}
return true;
}
function dynamicdropdownone(listindex)
{
document.getElementById("sub_subcategory").length = 0;
switch (listindex)
{
case "Wordpress" :
document.getElementById("sub_subcategory").options[0]=new Option("Please select Year","");
document.getElementById("sub_subcategory").options[1]=new Option("Wordpress Version1","wordpress_version1");
document.getElementById("sub_subcategory").options[2]=new Option("Wordpress Version2","wordpress_version2");
break;
case "Magento" :
document.getElementById("sub_subcategory").options[0]=new Option("Please select Year","");
document.getElementById("sub_subcategory").options[1]=new Option("Magento Version1","magento_version1");
document.getElementById("sub_subcategory").options[2]=new Option("Magento Version2","magento_version2");
break;
case "Strauts" :
document.getElementById("sub_subcategory").options[0]=new Option("Please select Year","");
document.getElementById("sub_subcategory").options[1]=new Option("Strauts Version1","strauts_version1");
document.getElementById("sub_subcategory").options[2]=new Option("Strauts Version2","strauts_version2");
break;
case "Hibernate" :
document.getElementById("sub_subcategory").options[0]=new Option("Please select Year","");
document.getElementById("sub_subcategory").options[1]=new Option("Hibernate Version1","hibernate_version1");
document.getElementById("sub_subcategory").options[2]=new Option("Hibernate Version2","hibernate_version2");
break;
case "Prototype" :
document.getElementById("sub_subcategory").options[0]=new Option("Please select Year","");
document.getElementById("sub_subcategory").options[1]=new Option("Prototype Version1","prototype_version1");
document.getElementById("sub_subcategory").options[2]=new Option("Prototype Version2","prototype_version2");
break;
case "jQuery" :
document.getElementById("sub_subcategory").options[0]=new Option("Please select Year","");
document.getElementById("sub_subcategory").options[1]=new Option("jQuery Version1","jquery_version1");
document.getElementById("sub_subcategory").options[2]=new Option("jQuery Version2","jquery_version2");
break;
case "Marc Hendricks" :
document.getElementById("sub_subcategory").options[0]=new Option("Please select Year","");
document.getElementById("sub_subcategory").options[1]=new Option("2013-2014","2013-2014");
document.getElementById("sub_subcategory").options[2]=new Option("2014-2015","2014-2015");
document.getElementById("sub_subcategory").options[3]=new Option("2015-2016","2015-2016");
document.getElementById("sub_subcategory").options[4]=new Option("2016-2017","2016-2017");
document.getElementById("sub_subcategory").options[5]=new Option("2017-2018","2017-2018");
break;
default:
document.getElementById("sub_subcategory").options[0]=new Option("Please select Year","");
break;
}
return true;
}
</script>
</head>
<body>
<div class="sub_category_div" id="sub_category_div">
<script type="text/javascript" Wrestling Level="JavaScript">
document.write('<select name="subcategory" id="subcategory" onchange="javascript: dynamicdropdownone(this.options[this.selectedIndex].value);"><option value="">Please select Wrestler</option></select>')
</script>
<noscript>
<select name="subcategory" id="subcategory" >
<option value="">Please select Year</option>
</select>
</noscript>
</div>
<div class="sub_subcategory_div" id="sub_subcategory_div">
<script type="text/javascript" Wrestling Level="JavaScript">
document.write('<select name="sub_subcategory" onchange="javascript: urlRedirectTo(this.options[this.selectedIndex].value);" id="sub_subcategory"><option value="">Please select Year</option></select>')
</script>
<noscript>
<select name="sub_subcategory" id="sub_subcategory" >
<option value="">Please select Year</option>
</select>
</noscript>
</div>
</body>
</html>
|
|
|
|
|
codeguy1 wrote: Right now all the alert does is displays the final selection which is the year but I want all the selection information to be put into the alert. Then you need to pass that information into the function that is creating the alert.
codeguy1 wrote: I can't seem to figure out the code to create an I-frame. If you google javascript create iframe I'm sure you'll find a ton of examples. However, I would suggest instead using a div and using jqueryui to pop it up as a dialog.
Social Media - A platform that makes it easier for the crazies to find each other.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
I tried passing information into the function but when I try to make selections on the webpage it won't even let me select the wrestler or year. Here's my code.
function urlRedirectTo(wrestlinglevel, wrestlername, year)
{
alert('Here are all the wrestling videos for '+wrestlername ' ' +year ' ' +wrestlinglevel);
if('Varsity' == wrestlinglevel, 'Marc Hendricks' == wrestlername, '2013-2014' == year)
|
|
|
|
|
Does this code work?
codeguy1 wrote: when I try to make selections on the webpage it won't even let me select the wrestler or year. It's your code so you need to change it so you can select what you need.
Social Media - A platform that makes it easier for the crazies to find each other.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
No my code isn't working and that's why I'm asking for assistance in making my code work I'm a newbie to javaScript and I've been stuck on this problem for over a week and I'm totally lost. I tried what you suggested and searched google but nothing I've seen looks like the issue I'm dealing with. I'm really desperate for guidance!!!
|
|
|
|
|
codeguy1 wrote: No my code isn't working and that's why I'm asking for assistance But the code you just showed was the code displaying the alert. You need to show the code that is calling that function. Why aren't you able to pass in the values? You said you could pass one value in so why not the rest of the values?
We're happy to help but I don't know where you are stuck or why.
Social Media - A platform that makes it easier for the crazies to find each other.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
I apologize I'm so lost. Here is my code attempting to pass values to the alert I know it's wrong just please let me know what's wrong with it.
function urlRedirectTo(wrestlinglevel, wrestlername, year)
{
alert('Here are all the wrestling videos for '+wrestlername ' ' +year ' ' +wrestlinglevel);
if('Varsity' == wrestlinglevel, 'Marc Hendricks' == wrestlername, '2013-2014' == year)
I'm not sure I'm even begging to pass values to the alert or if I'm doing nothing with the values.
|
|
|
|
|