how to upload image from mongoose schema to mongodb? - mern

Hi all i am new to MERN Stack Development. So please tell me how to upload a image from mongoose to mongodb. And also i need to know how to get the image path dynamically??.
Please suggest me some docs so that i can understand the concepts by depth. I have searched all over internet but i couldn't find what i needed.But i don't want to use "fs" in here. I need another way to upload the image.
This is my model
var list = new User({
Name: "sri",
Age: 11
list.image.data=fs.readFileSync(req.file.path);
list.image.contentType='image/png';
list.save()
})

Related

Populate word document from html form

I am new to web development and need your help to figure out how to use the form in HTML and use the data to populate the said field in a word document. Any advice on how to approach this problem is highly appreciated. It would really help if you could post a live example for the below. Please,do let me know if any further explanation is required.
As a new developer, I want to advise you that you are getting into some challenging territory here and many of the solutions might require some heavy experience with programming and MS Word. In this forum, there are many options you can try, but from what I gather you will need to learn about macros.
The second option you could try are some services that will do this for you for a fee. Here are two options. Check out Formstack or Jotform
If you use this type of service, you would create a form action within your html code that will merge the data from the form into the Microsoft Word Document using merge tags.
The third option you can try is using Javascript within the form to populate the Word Document. The code would look more like this:
function Export2Word(element, filename = ''){
var preHtml = "<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:w='urn:schemas-microsoft-com:office:word' xmlns='http://www.w3.org/TR/REC-html40'><head><meta charset='utf-8'><title>Export HTML To Doc</title></head><body>";
var postHtml = "</body></html>";
var html = preHtml+document.getElementById(element).innerHTML+postHtml;
var blob = new Blob(['\ufeff', html], {
type: 'application/msword'
});
// Specify link url
var url = 'data:application/vnd.ms-word;charset=utf-8,' + encodeURIComponent(html);
// Specify file name
filename = filename?filename+'.doc':'document.doc';
// Create download link element
var downloadLink = document.createElement("a");
document.body.appendChild(downloadLink);
if(navigator.msSaveOrOpenBlob ){
navigator.msSaveOrOpenBlob(blob, filename);
}else{
// Create a link to the file
downloadLink.href = url;
// Setting the file name
downloadLink.download = filename;
//triggering the function
downloadLink.click();
}
document.body.removeChild(downloadLink);
}
Export HTML Table Data to Excel using JavaScript
HTML Content:
Wrap the HTML content in a container you want to export to MS Word document (.doc).
<div id="exportContent">
<!-- Your content here -->
</div>
Last option would be using PHP, and I recommend watching this video by CodexWorld and reviewing the post that goes along with it here. This is a challenging concept, so I would encourage you to take your time.
Hopefully this will help and best of luck.
Well, I don't know how to exactly do that, I am also a beginner like you. What seems to help you might be connecting your form with Google Sheets. The Google Spread Sheet will store all data submitted via your form. You can then use this data wherever you want.
There is an open source project for this task, you can do that by following the steps stated here: https://github.com/dwyl/learn-to-send-email-via-google-script-html-no-server
You can see it in action here: https://nisootech.vercel.app/#contact-me
There are two parts in your application
Enabling user to input the values in frontend. Which you can build using any frontend technology stack eg: HTML and Plain Javascript(Required for calling the Services), React JS, Angular etc.
Backend Service which will basically does the heavy work
Receiving the input from user.
Creating Word file using any libraries such as
Generate word files using Apache POI ,
Using Node.js to generate dynamic word document using Database value
Downloading the file after its completely generated using the values supplied by user.
download a file from Spring boot rest service
how to download file in react js
For the Backend service you can use technologies like Java and Springboot, Python, Node Js etc.
Building Restful webservices using spring
Use Technology in which you are more comfortable and start building. These Links and documentation you can use to start from basic.
Suggest you to breakdown your problems focus on each specific areas and do the development as per your smaller problems and integrate them later.

Accessing filesystem in Angular 5, using electron

I'm building an simple stand-alone angular application in which u can submit information.
This information needs to be saved in a local JSON file that's in the asset folder. I know Angular runs in a web browser that's why I use electron to build it. The problem is that i can't figure out a way to edit the JSON files in angular 5 using electron (local).
I have tried the solutions mentioned in this post, But they didn't work for me, any other solutions?
After having this problem for quite some time i finally figured out how to solve it:
you need to put this in script tags in your index.html
var remote = require('electron').remote
var fs = remote.require('fs');
and in every component you want to use it you need to declare it globally
declare var fs: any;
then you can use it!
was quite a struggel to figure it out...
Because it's just JSON data, might I suggest using localStorage instead? Then, you can do something like:
...// Code that creates the JSON object
var theJSONdata = jsonObj.stringify(); // conver the object to a string
window.localStorage.setItem('mysavedJSON', theJSONdata)
;
Later, when you need to load the JSON to edit it or read it, just use:
jsonObj = JSON.parse(window.localStorage.getItem('mysavedJSON');

Create an API directly from a data source

I need to create my own REST API.
I just saw strongloop and loopback and I thought it will be perfect for my project.
In fact, I was able to get mysql connected using strongloop. However, I had to create something called a "model" and I did it. But, it was like creating a new model from scratch and use it for persisting on the Datasource.
Instead, what I was looking for, is to get a REST API directly from my model on the DB.
I mean taking the models from each table on the DB and then set them up as web services.
Is that possible?
I am newbie on these technologies, although I think it is an interesting question.
Thanks
I'm not sure of a Node tool to do what you're asking, but in other languages / databases you have some choices!
The only one I'm really familiar with is postgrest.
postgrest: You import your data into a Postgres database (similar to MySQL), and it generates a REST API on top of your tables instantly. Bam. Done. I've used this and it was amazingly awesome. You can also deploy it directly on Heroku.
StrongLoop actually has a "discovery" tool for just this purpose! Read up on that page, but here's the basic code to do it. Just drop this code in a file inside /server/boot/ (the docs are wrong on that, it must be in the directory I mention). Of course, you'll need to tailor it for your use case:
var loopback = require('loopback');
var ds = loopback.createDataSource('mysql', {
"host": "yourhost",
"port": 1234,
"database": "foobar",
"username": "someuser",
"password": "somepass"
});
// Discover and build models from a given table
ds.discoverAndBuildModels('PERSON', {visited: {}, associations: true},
function (err, models) {
// Now we have a list of models keyed by the model name
// You only need the rest of this if wanted to inspect what came in...
// For example, you could find the first record from the table
// and verify info or something.
models.Person.findOne({}, function (err, person) {
if(err) {
// handle this if need be...
console.error(err);
return;
}
// Some code using `person`
});
});
Good luck!
I was supposing "discovery tool" was to find out pattern, cluster or whatever else thing into the data. But following
the recomendation of #jakarella I went with more depth.
It was even easier than that, because you can do everything via StrongLoop Arc (GUI). I always prefer cli
but to have a general look of it, sometimes is better to start with the GUI if you don't have too much idea about the subject.
Anyway,
first of all you would need to connect your datasource before (installing previously the driver).
After that, through StrongLoop Arc you can do "discover the models" choosing your tables (taking care of run Arc and restarting every time
you get a new model) and that's it, you get an API over your Datasource
(for testing go to the explorer).
I described before generally the main tasks but if anyone needs more detail pls let me know. Hope this helps to anyone else who is looking to do
something similar
thanks guys for the interest.

Consuming SSIS Data Profile XML

I am attempting to read the output of an SSIS Data Profile task into an MVC app. To work out the kinks, I wrote a small console app to test the parsing of the xml file.
I used the following link:
http://schemas.microsoft.com/sqlserver/2008/DataDebugger/DataProfile.xsd
to download the .XSD file that should describe the .XML file that was generated in the Data Profile output file.
I then ran xsd.exe to create a C# class to include in my console app.
Following is my very simple test code:
XmlSerializer xser = new XmlSerializer(typeof(DataProfile));
DataProfile dProf = xser.Deserialize(new FileStream(#"D:\InputFiles\ProfilerDataCVD.XML", FileMode.Open)) as DataProfile;
if (dProf != null)
{
var profs = dProf.DataProfileOutput.Profiles;
foreach (ColumnValueDistributionProfileType c in profs)
{
Console.WriteLine(string.Format("Column Name: {0}, RowCount: {1}, Distinct Values: {2}", c.Column.Name, c.Table.RowCount, c.NumberOfDistinctValues));
}
}
In that code, "dProf" is never NULL, but always empty. Any assistance at getting data in dProf would possibly save a life, because I am about to jump off of a cliff trying to figure this out!
If there is some obvious XML thing that I am missing, I will be the first to admit that this is not my strongest suit. Feel free to chastise me at will as long as you tell me how to make this return data.
Regrettably, no one has been able to answer this question. And I would still really like to understand why something so simple does not work.
In the meantime, anyone else struggling with the same issue should check out the following link on MSDN forums for an alternative way of doing the same thing.
http://social.msdn.microsoft.com/Forums/en-US/sqlintegrationservices/thread/a282bb60-c099-4656-bf71-52ddc6153c28
I implemented it yesterday in just a few minutes and it works great.

Post an object of type Reference

I have had this problem for some time now and I have seen others have it as well. It has to deal with posting your custom objects that you create in Open Graph to post with your application. I am having this problem primarily on all platforms, but right now let's say I am using Android. If someone has accomplished this in C# or on IOS or even in PHP please post your answer.
An Example:
I have an object that posts a meal to Facebook. Let's say its properties are the following.
mealName = "Lunch"
mealType = "Vegetarian"
mealLocation = "Somewheresville, OH"
Now I have another object in my Open Graph and it is called DailyFood. It has properties such as the following.
day = "12/01/2012"
meal = "MyCustomMeal" // This references a meal object
Now when I go to post that I try to do the following in Java.
//Build Meal
JSONObject mealData = new JSONObject();
mealData.put("mealName", "Lunch");
mealData.put("mealType", "Vegetarian");
mealData.put("mealLocation", "Somewheresville, OH");
Bundle params = new Bundle();
params.putString("day", "12/01/2012");
params.putString("meal", mealData.ToString());
AsyncFacebookRunner request = new AsyncFacebookRunner(facebook);
This is where I generate the following error code.
{"error":
{"message":"(#3503) is an invalid value for property
\"meal\" with type \"Reference\"","type":"OAuthException","code":3503}}
Now I know that it says OAuthException but I am able to post feeds to Facebook with this app just fine. If anyone else has experienced this error on any platform and has found a solution please post it here.
Thanks!
So the answer to this question is that you actually need a website available for your app to be able to reference what its posting to Facebook. In the docs, I at least, wasn't able to find out where this was noted.
according to this official video you must have the web application to post the action using open graph,no matter in which platform we are working android,ios etc
as it fetches the meta tags and properties from the web url only which works as refrence.