I would like to get an image xpath, but this image encoded, is any way to get a content? this encoded image file have details like this:
data:[<mediatype>][;base64],<data>
data:image/png;base64,iVB.....
I'm not sure exactly what you want to do, but if you have access to an XPath processor that implements the EXPath Binary Module (http://expath.org/spec/binary) then it should be possible.
Related
I have an application that gets a JSON file via a web service. The JSON is fairly large, and represents a Person object, with typical properties such as first name, last name, title and image for example. The person's image is stored as a base64 field in the JSON. It is bound to an image tag using Angular. So for example, the HTML looks like this:
<img ng-src="data:image/jpeg;base64,{{ person.fileImage }}">
When the end user right clicks on the image and chooses to save the image, the browser defaults to the name "download.jpg". What I need to do is name the image so that when the user right clicks and chooses to save, it gives a meaningful filename, e.g.:
todd.davis.jpg
I'm not sure how to make this happen. I've seen some solutions that use an anchor tag with a download="todd.jpg" parameter, but that is not working for me. I think it expects an actual URL and in this case, I don't really have one. The image data is just embedded in the JSON.
Is there a way to manipulate this so that I can add a name to the image for saving purposes?
How can I get an image on a webpage with Selenium and encode it to a Base64 string which gets added to a variable? I'm using Selenium C# but any language will probably work.
I am not quite sure what you are asking. What do you mean by "get an image on a webpage"? Do you mean:
grab a screenshot of your page and compare it with some given value? or
take a screenshot of specific element on webpage?
download an image contained in (ie) <img> tag and do something with it?
For taking screenshots, it is widely disucessed here. Although mostly java solutions, they probably could be ported to C# with ease. If what you need is nr 3, then get the URL (ie using xpath //img[#id=\"yourId\"]#src ) and download it using something like WebClient and convert that to base64:
var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(plainText);
var baseString = System.Convert.ToBase64String(plainTextBytes);
This code will helps you, I am using it for my own report, instead of storing report in seperate location, better to convert into base64 form and add it to report.
String Base64StringofScreenshot="";
File src = ((TakesScreenshot) driverThread).getScreenshotAs(OutputType.FILE);
byte[] fileContent = FileUtils.readFileToByteArray(src);
Base64StringofScreenshot = "data:image/png;base64,"+Base64.getEncoder().encodeToString(fileContent);
I have a model that has a property like "SomeUrl", it's an absolute url with some parameters in it, something like this for example: http://www.someexternalsite.com/q?param1=value1¶m2=value2
My view takes a List and I am trying to use these url's in an anchor tag like this:
my link
The url is being encoded and ends up coming out like this:
http://www.someexternalsite.com/q?param1=value1¶m2=value
How do I stop it from doing that?
Not encoding the & would result in invalid html. In this case the html is correctly encoded. If you want to render a string not encoded use:
#Html.Raw(...)
Change your link to this:
my link
I'm designing a news-reading app and using the NavigateToString() of a webbrowser to show some string. Now I want to implement the off-line reading function, the html string had already been downloaded, except the image.
Windows phone has implemented the image-cache function, once the Image is requested, it had been cached. But now problem is that, all the html strings are stored in a array, some of those html strings hadn't been shown throught the navigateToString(), namely the imgs in those string couldn't show up if the internet is disconnected.
So I'm wondering how to cache the imgs in the webbrowser?
thanks,
ellic
It ain't gonna be easy or pretty.
Here's one thing you can do...
Parse the HTML using something like the HtmlAgilityPack. Linq should be a good solution for finding all the images. If you want to use xpath, you can do that too.
Find all Images in the HTML and use a WebClient (or better yet, a WebRequest) to fetch them.
Save them as part of your database that you use to store your HTML strings (say, Base64 encoded if your medium needs to be strings, key'ed by the URI to the image);
When you want to display the offline HTML, again, parse the HTML and replace all references to images with the data protocol equivalent of your cached images.
I am trying to retrieve zip file from FTP, unzip it, and get xml file and image file from them and parse the xml, display the contents of xml and image.
byte[] image = ftpClientService.getThumbnailInZip(customer.ftpUser,
customer.ftpPassword, customer.ftpHost, customer.ftpToWrapDirectory,
fileName)
FileOutputStream fos1 = new FileOutputStream("zip.img")
try {
fos1.write(image);
} finally {
fos1.close();
}
return [
command: this,
fileName: fileName,
applicationName: applicationName,
contentProvider: contentProvider,
operatingSystem: operatingSystem,
handSets: handSets,
zipImg:"zip.img" ]
I could finish the xml part successfully and image also I am able to retrieve from the zip in a byte format( i could convert it to a file using file outputstream),
Now I am stuck in sending the image to gsp and to display that. Any inputs are much appreciated.
Thanks
If you want to use the image only once, meaning it should always be extract from the zip file, then embedding the img in base64 format into the webpage is a good option here because you don't need to worry about the image file after sending that base64 encoding value to gsp.
If you still need that image file to be used by other http requests then you should extract the images to a folder and send the list of img paths to gsp.
You can either
point img src="${g.createLink(action: 'a', params: [p: p])}" to some other action (with createLink) that will cache the image on your server side,
or embed it right into HTML, like in this question.
Browsers can render byte arrays if you specify the format.
Having a variable image in the model sent to the gsp of type byte[], this is the way to render it HTML:
<img src="data:image/png;base64,${image.encodeBase64()}"/>
You also need to specify if it's image/png or other format.