how to upload canvas image using struts2 [duplicate] - javascript

I need to retrieve rows in database with a image saved in byte array. How do I display the image using Strut2?
I have displayed it by using custom result. I passed the id and make an action search for it in the database. My problem is how to invoke this several times? I have an action that retrieve all the rows. How to call display image action from the list action? Or is there a better way to achieve this?
JAVA
My action has an list of the objects I want to show on JSP.
JSP
First way: I use iterator tag and on each iteration I want to display the image which is in byte array. I want call the action to retrieve the image here.
Second way: I tried this post and it is not working for me.
<img src="data:image/jpg;base64, <s:property value="imageData"></s:property> />" >
Image data is the image in string.

To retrieve rows in database there's many ways but all of them utilize JDBC API. You can map the object as an image array containing bytes or blob or clob data that you persist in the database.
Displaying the images required to send it to the browser. In the Struts2 there's a stream result type that could be used to output the image data to the browser.
Or use the Servlet API to transmit the data on the JSP similar like in How to send and display image from action class to JSP in Struts 2 answer.
Combining the experience from the answers that you already enlighten in the question to stringify data you may achieve suitable results.

Related

Retrieve image from MYSQL and display it in HTML

I am currently working on an online text editor for writing wikipedia-like articles.
Therefore I have <input type="file" accept="image/*">in HTML.
What I want to do is save the article as text to a MYSQL database and later, when displaying the article take the text from the database to show it in the page.
But how would I do this with the Images?
What's the best way to save them to a database?
And how can I retrieve them from the DB and display them?
I think wikipedia just displays an img-tag with an link to the image as source:
<img src="link_to_image">
but how could I create such a link?
First of all you can store an image in the DB but it's not a good practice.
There are already posts about this: Example
What I would do, anyway, is:
store the image in a blob column (maybe as base64 string)
First you have to convert the image, then store it in the DB. Assuming you are using PHP, you could do something like this:
$base64 = 'data:image/' . $type . ';base64,' . base64_encode($imageData);
Then store it in the DB with a simple insert.
retrieve the image and return it as a response of a service
In mysql you should just do a select and then return it via (I assume PHP service)
browser side, to display the image: Example
This differs from what you want to do
<img src="link_to_image">
I had to do implement a solution similar to this one and works fine enough. You can encounter problems if the image is large in size (2MB for example) or if you want to fetch multiple images at once.
To achieve what you want to do, the best solution is to store the image in a file system that allows you to serve the files or , for example in AWS S3, and just save the image URL in the DB.

Using Select 2 drop down for large data more than 10000 Search

Hello every one i want to use select 2 drop down which can easily filter
more than 10000 record butt in the given link
http://jsfiddle.net/a8La61rL/10/
using script a large function that is not good to use in every page
is there is any to use this script in a separate file and send list of array
objects to this method for populating and searching
This is possible with the following steps.
1- Make an ASPX webservice or Web page function which will fetch a list of these records from a file using C#/Vb file handling and return in JSON array.
2- Use jQuery $.ajax method to fetch this json array from ASPX function or Webservice.
3- Bind the select2 in jQuery success event.
This will become a call, and on every page you can include this script and bind data. For better performance, you can also fetch first time from file and save in session or cookie and whenever any other page will call, it will fetch from session or cookie. I can explain further if required.

How to display image object using Javascript / Jquery

I've got an object called 'output' that I need to display on the page. It is an image object. I tried to use the following code but it doesnt work. Any advice greatly appreciated.
document.getElementById("imageDiv").appendChild(output);
<div id='imageDiv'></div>
When I alert the object I got the following:
{"result":{"output":"data://path-to-file/background-32.png"},"metadata":{"content_type":"json","duration":9.845787767000001}}
How do I actually display the file?
You are using the ColorfulImageColorization API from Algorithmia.
It turns out that this service doesn't actually return the image data or a true URL path to the resulting image. Instead, it returns a pointer to where the image is stored in your data collection that you have set up with them. You can read about the various types of data collections and such on their Hosted Data page here
Also, from their comments sectiion:
Nir_Photomyne: Hey there! :) how to access the output using JS? I get the out put url but then what?? HELP
deeplearning: #Nir_Photomyne: There are a couple options depending on what you want to do with the images. The best option is probably to set the output location to s3,after setting up an s3 data connector at https://algorithmia.com/data
.
My personal opinion?
I'd see if I could find a similar API that is more straight forward and simply sends the image data in the response instead of storing the data.
http://jsbin.com/diwekox/edit?html,js,output
Do you just forgot the put on the image source attribute or something else?

Load a js image

I am writing an Android RSS reader. It uses webview to display each article. To identify the most read news I load a fake image from my server like:
<img src='http://example.com/update_read_count.php?article_id=1234'>
At the server I will increment the view counter.
Is there a way I can respond back with the number of times it has been read. Or is there a way I can update a DOM element inject this count in the page?
Since it is an image, the only way you could do that would be to generate an image containing the text you wanted on the server. e.g. with this function.
If you wanted to update the DOM, you'd need to get the data in a more useful format. Using XMLHttpRequest to fetch the data and then returning it in JSON format would be traditional.

How to retrieve images from database using jquery and servlet

I need to retrieve the images which is stored in my oracle 11g R2 database. I'm trying to retrive the images using Jquery and servlet, And placing into the css division. But I'm a newbie in this. I know using json objects we can do this stuff. Please anyone tell me how to do
Make a request that returns a list of the names of all images (so that you know what to retrieve)
Make a servlet that serves images - gets the name as GET parameter, looks it up in the database (e.g. via JDBC) and streams the result back into the response.getOutputStream(), and set the correct content type

Categories

Resources