Rails - image not rendering in mail - ruby-on-rails

I'm Trying to attach an image in the ActionMailer... it rendering the image in the mailer preview but when i send to the actual server... the image is not rendering... when i inspect the path of the image it's shows the different path... can someone help me to fix this.
ActionMailer body image tag
<%= image_tag("my_pic.jpg") %>
preview path
src = "/assets/my_pic-f2af962f1d8a8c36762b9de24ab569c8aab52211bb1be694d89008c163faf528.jpg"
image src in server
src = "https://ci3.googleusercontent.com/proxy/r4Dwrpzp5gcpY42JsXyaQatlH1fYeCgqR12apCq7frlKRKzP1Bg_CF9I7mxzJPI_TISv7JyUn-9TQAXW0r3ytwftniCyRwXC_tV6XHxFTdGu8RaEk3lQXfyy2MbAjNJWk5LRyUrBHNjY9XgGdpGTHO5gRA=s0-d-e1-ft#http:///assets/my_pic-f2af962f1d8a8c36762b9de24ab569c8aab52211bb1be694d89008c163faf528.jpg"

Related

Inside Splash, how to use src attribute to append to a url

------------ORIGINAL QUESTION------------------
In my Splash Script, I am trying to use "splash:go" on a new url that is based on the "src" attribute of an "img" tag. How can I access this "src" relative url and join it to a start_url?
For example, imagine that the img element has the following contents:
<img id="ImageViewer1_docImage" onload="BlockerResize('ImageViewer1_ContentBlocker1','ImageViewer1_WaterMarkImage');" src="ACSResource.axd?SCTTYPE=ENCRYPTED&SCTKEY=gMYed5OWqcT9I1Y2fM85DvB48X5U1DQ5mOUiJoUH4rioyau0nJdxt0PHFfGVTMiUsork/YD+Cw0F6ZzcviP4sG09xrqWM8/zJlyEeVRFkKXVnkyHYWgwNJzCSUE4Kh4yCsqw6mCuIxWxPj6BAI7Hbw==&CNTWIDTH=849&CNTHEIGHT=684&FITTYPE=Height&ZOOM=1" alt="Please wait" style="border-width:0px;cursor: url(images/Cursors/hmove.cur); z-index: 1000">
Here I am trying to extract the src attribute and add it to start_url:
https://i2a.uslandrecords.com/ME/Cumberland/D/
I want all of this inside the Splash script. I need it to be done inside of Splash because otherwise I lose my security/encryption or something--it renders "Bad Data" instead of the new webpage. Do you have any recommendations?
------------UPDATE------------------
So I managed to obtain the url I needed from the src attribute using the following code:
var = splash:evaljs("document.getElementById('ImageViewer1_docImage').src;")
splash:go(var)
However, the problem is that this is producing a error message. All I find in the snapshot is a white page with the following message:
Failed loading page (Frame load interrupted by policy change)
https://i2a.uslandrecords.com/ME/Cumberland/D/ACSResource.axd?SCTTYPE=ENCRYPTED&SCTKEY=gMYed5OWqcSvEWOJA6wGVmb642s2oZHqkYmT6VTpORTzMY7CgvDU5jsjJG/xp0X3eQ9BiDnbaTdAmISeLkC3hyjxGjcSnXOKgGDa8cI2fniY0ILT+NqvQToMGIB+/X3ZIs7Q+D4ppTSZGYZ2L4M/
Webkit error #102
Any idea why?
The image src attribute is exactly the URL you need to access or as stated by the question title you need to append it to some other URL parts?
If that is the case, you can do it by '..'
Ex.: splash:go(base_url..var) -- concatenation
ISSUE RESOLVED:
Here is the solution. The GET request was breaking down because it didn't know how to render the image in html given the webkit settings. If you execute the GET request without rendering the page, the response.body has the image.
CODE:
local response = splash:http_get(var)
return {
body = response.body
}

Grails svg image href referring the png is not showing

This is difficult to explain. I needed some fills in Coreldraw that I liked and saved as SVG. When Coreldraw saved my svg, I got one folder called soil_Images with soil_ImgID1.png inside and soil.svg. And I put inside of web-app/images project. For some reason, the image png is not shown.
I have my svg like in my gsp:
<image x="177" y="76" width="36" height="23" preserveAspectRatio="none" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="/projectName/images/soil.svg"></image>
And my soil.svg has another image tag that shows true image that I want:
<image x="44" y="29" width="8156" height="11707" xlink:href="soil_Images/soil_ImgID1.png"/>
I tried to add a contextpath like: ${application.contextPath}/images/soil_Images/soil_ImgID1.png.
That didn't work. What am I missing?
In chrome resources, the image hasn't been downloaded.
Building off of Matt Busche's blog post on using the asset pipeline with SVG and PNG fallback images, try pointing to the asset pipeline location instead of hardcoding. Note the assetPath with src (the relative path you are using if not the default asset pipeline image location) and the name of the image.
<image xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="${assetPath(src: 'imgs/' + logoSVG)}" src="${assetPath(src: 'imgs/' + logoPNG)}"></image>

Inline Attachment image is not displaying in Rails 4

I've been trying to show inline attachments in my mail (logo),
I've seen many answers on the community, nothing seems to be working for me,
Mail is going fine,I can see the text but unable to see image
this is my mailer:
path variable contains path to logo
attachments.inline['logo.png'] = { content: File.read(path),mime_type: "image/png" }
this is my view:
Welcome to my site
<%= image_tag attachments['logo.png'].url%>
Please Help,I've been pulling my hair for hours now on this.
In your mailer try:
attachments.inline["myimage.png"] = File.read(File.join(Rails.root, "app", "assets", "images", "myimage.png"))
your view code is correct.
I've been using this code successfully with one image, though there may be a bug in rails. Check: https://github.com/rails/rails/issues/2686

Image not rendered in .doc file

I have a template that have some images one from file system and other are from project images folder.
Images in the template that are coming from the images folder of my grails application is shown perfectly in the doc file. I am using below code to render these images:
<img src="${g.resource(dir: 'images', file: 'phone-1.gif', absolute: true)}"/>
But I have an image that is coming from file system(/opt/profileImages folder). Using below code to render this image in template:
View:
<g:img uri="${g.createLink(controller: 'personalDetail', action: 'showUserProfileImage', absolute: true)}"/>
Controller:
def showUserProfileImage() {
User user = springSecurityService.currentUser as User
String profilePicturePath = "${grailsApplication.config.profilePictureDirectoryPath}/${user?.profilePicture?.fileName}"
File file = new File(profilePicturePath)
def img = file.bytes
response.contentType = user?.profilePicture?.mimeType
response.outputStream << img
response.outputStream.flush()
}
This is working fine, showing profile image in the browser as well as in the pdf that I downloaded using grails rendering plugin.
But problem is .doc format file. When I download the template in doc format then image is not shown.
Screenshot:
Can someone please tell me where I am wrong?
Or is there any other way to do this?
Here you are trying to access image src out of your application context.
So your source should look like this.
<g:img uri="${profilePocturePath}" width="93px" height="100px"/>
Refer this
<mvc:resources mapping="/images/**" location="file:/absolute/path/to/image/dir"/>
Kanwal Nain Singh solution works only if server is running in local but if I download template in doc format from remote then again image is missing. The problem is doc search image in local machine(/opt/profileImages folder).
Following code is working perfectly:
Action:
def showUserProfileImage() {
String profilePicturePath = "${grailsApplication.config.profilePictureDirectoryPath}/${params.id}"
File file = new File(profilePicturePath)
response.contentType = URLConnection.guessContentTypeFromName(file.getName())
response.outputStream << file.bytes
response.outputStream.flush()
}
Tag:
<g:img uri="${grailsApplication.config.grails.serverURL}/user/showUserProfileImage/${userImageName}"/>

Get the filepath of an image inserted into TWebBrowser in edit mode

When you insert an image into a TWebBrowser in edit mode, how do you get the filepath of the inserted image? When an image is inserted it includes the full path to the image in the html source, but in my case I need to modify the html source to only include the filename.
EDIT:
This is the html source after the image is inserted:
<IMG border=0 hspace=0 alt=delphi align=baseline
src="C:\Images\delphi.bmp">
I need to change
<IMG border=0 hspace=0 alt=delphi align=baseline
src="C:\Images\delphi.bmp">
to
<IMG border=0 hspace=0 alt=delphi align=baseline
src="HTML\delphi.bmp">
Yes I can get the path from the html but I'd like to try to copy the image file to the HTML folder then change the path to the HTML folder after the image is inserted without parsing the html. If the filepath can be obtained after the image is inserted I can add the code to copy the file to the HTML folder so that the image appears in the webbrowser with the new path...
Have you tried using the browser's DOM interfaces to read the src attribute and update it to what you want? Specifically, look at the src property of the IHTMLImgElement interface.

Resources