Adding Image in a Website Using Express - image

I am making a website with nodejs and express, I want to add an image among text from a local src. Much like how if I were using html to mimmick a Wikipedia article I would do this:
<p> Coins are really cool, people use them as a heavy kind of money. Obviously paper money is better though</p>
<img src="uploads/pictureofcoins.png" alt="nicklesAndDimes">
<p> some pictures have coins of important people on them, sometimes just birds though </p>
In Expressjs the process seems to look something like this. First I have an app.js file where I provider a folder directory. Then you set a variable that is the image pointing to the folder directory. I believe you do this by the following.
app.use(express.bodyParser({ keepExtensions: true, uploadDir: __dirname + '/public/uploads/' }));
the my jade file looks almost identical to the html
p Coins are really cool, people use them as a heavy kind of money. Obviously paper money is better though
img(src='localhost:3000/public/uploads/pictureofcoins.png')
p some pictures have coins of important people on them, sometimes just birds though
I know that the pictureofcoins.png image is in the uploads folder. There something coneptual I am not getting, the icon appears as a broken image icon in chrome.

You are using a full url, in that case you need to specify the protocol as well.
So try adding http:// or // to your image source url.
Note that when using a full url make sure you don't hardcode host and port. It is possible to retrieve that information from the http request.
You can also try /public/uploads/pictureofcoins.png as a relative link to make sure it works regardless of host and port.

Related

Somebody Is "Hijacking" My URL

I track traffic to the domains that I own through a "home brew" cookie system. One one site, I have noticed that I get a lot of HTTP referer traffic from one particular domain (http://www.getbig.com/). I did some sleuthing, and found out what this person has done. This person has attempted to use my sites logo as their avatar on a forum. However, instead of linking to the image in the "img" tag:
<img src="http://www.example.com/image.jpg" width="" height="" alt="" border ="" />
they have linked to my main domain name:
<img src="http://www.example.com/" width="" height="" alt="" border ="" />
Every single time a page is loaded where this person has posted in this forum, a new hit gets registered. This is artificially inflating my visitor statistics, and I would like to stop it. If they had simply linked to the image, I could just change the image name, but they have linked to the site itself and I am not sure what to do. Aside from sending them a "cease and desist", what technical options do I have?
The principle is called hotlinking – or at least it is when done correctly, as you pointed out. There are a few solutions to "stop" it from happening.
The most common one is to serve a different page or image instead of the expected one. Apache's mod_rewrite (or similar) allows you to rewrite URLs based on particular criteria, such as the referer header in this case. You will need to be at least allowed to create your own .htaccess file. There are tools to help generate the .htaccess content.
A less informative way to do this would be to deny access via environment variable. First check the referer header with SetEnvIf and deny access based on it. This would only return a HTTP#403 response code.
If you don't have this sort of access, you could read the referer header at the application level and make a decision there. This might only be a partial solution depending how the content is delivered (i.e. request handled by the webserver or an additional application layer such as PHP).
Contact the user in question. This is less scalable and doesn't stop them if they don't agree with your kind request.
The first three are solutions to stop hotlinking in general. They can be adjusted to match only a particular referer.
In this particular case, I doubt any of these will have a significant effect unless you provide a picture in response. If the URI doesn't contain the actual image name but only the protocol and domain name, the browsers opening the page are unlikely to show anything relevant for the img tag at the moment. Providing a different content won't change this situation, unless it's an image. Serving an image explaining why you don't allow hotlinking (even if they request the main page) would probably have a more important impact on the user.
It is difficult to assess how your statistics will be affected by these solutions. Assuming they are collected on the main page, they could bring the data back to normal as that page won't be served anymore. If they're based on the access logs, it might be a different story.
What I would recommend is check out the Referer, and if it is coming from http://www.getbig.com/, instead of your website you serve the absolute filthiest image you can find on the internet.
It's much, much easier to just send them an email though.. (this is my actual advice).

CEWP to show images (HTML) works until I use grouping. Then I see the DIV tag

I'm fairly new to Share Point so forgive me if this is to easy for you guys, but I could not seem to find the answer anywhere and I am rather stumped.
I am currently trying to make a website to track if particular tasks go over their due date. I have a calculated column that leaves a DIV tag to the image of a red/yellow/green circle which is displayed by the javascript for a Content Editor Web Part (CEWP) made by Christophe on his site here:
http://blog.pathtosharepoint.com/2008/09/01/using-calculated-columns-to-write-html/
I was able to put his code into the CEWP and everything looks great when it is in a standard list.
But I want a web part version of this on the homepage for easy view. When I make the web part (of a view grouping by the image tag) and place on the main site all I see is the DIV tag! I made sure to put an identical CEWP on the homepage as well but i get as grouping:
+[columnName] : DIV>img title=blahblahblah>/DIV> (2)
Needles to say when I expand this it stays the same for all entries below
Any Ideas?
Thanks for your time :D
Nobody has responded, but I found the answer so hopefully this will save someone the hours of grief I had. This will seem ridiculous but just go with it.
In the calculated column instead of returning the type as text, return it as a currency. Sounds ridiculous BUT IT WORKS!!

ASP.Net MVC. Making Dynamic Images SEO Friendly

I have a website made to provide free web-based tools for making indie games. Currently, it only supports artists contributing to games. The features for helping artists consist of a set of artist community tools that allow artists to upload images based on a description, then we post that image in a gallery page. Other artists can upload their images and each image can have several revisions.
The way I chose to implement the image upload and display feature is by serializing uploaded images to a byte array and storing it in the database. When I need to display the image in the UI I just call a controller action I named "GetScaledGalleryImage" and pass in the image ID. That controller action takes the binary from the database and converts it back into an image, returning the requested image back.
This works very well functionally, but the problem I realized later is that the google crawler thinks all of my images are named "GetScaledGalleryImage" so if someone searches for "sylph" on google images, nothing comes up from my site, but if someone searches for site:watermintstudios.com getscaledgalleryimage, all of my images come up.
Here is an example of the URL that is being output in my HTML http://watermintstudios.com/EarnAMint/GetScaledMedia/68?scale=128
In the past, pre-MVC I would handle 404 errors and return content based on what was requested even if the page didn't actually exist. This would of course allow me to have the images pulled back by the image name (or description).
Is that the best way to do this? Or is there a better option? Something simpler would be better like if I could just do http://watermintstudios.com/EarnAMint/GetScaledMedia/Iris%20Doll?id=68&scale=128, but based on how google indexes images, would that give me what I need? Or do I need to provide image file extensions for maximum indexability?
Thanks all
It is important when doing Search Engine Optimization to always use alt="this is a crazy robot" for your images. This will help the crawler identify them. Note: always use alt, don't always name your images this is a crazy robot.

How to retrieve plain text from a formatted website to use in UIWebView

Not sure if what I want to do is possible, but what I am hoping to do is somehow gather certain pieces of text from a website, remove the header, footer, background, all formatting, and place it into my application in a scrollview or something similar...
I'll give you an example... Imagine I was making wikipedia's iPhone app, I want to download the information about the wiki on dogs, without the header, side bars etc, just the text. How would I go about doing this?
I understand that for this I have not provided any example code or what I've tried or started, but that's just because in this case I'm lost! That doesn't mean I want full chunks of code either. Any help will do. If this doesn't work, I will just have to make a 'mobile optimised' version of the webpages I want to include in my app.
Thanks
(Edit: the term I was trying to use was 'strip the web page of its HTML coding')
You may be going about this the wrong way, or perhaps even asking the wrong question.
Does the target website have an API or datafeed of some kind?
Can you get the information you need in JSON or XML format directly from the site?
I think you've misunderstood the technology. HTML is merely the framwork on which the formatting and data is hung.
Parsing the HTML page seems like an awfully big headache, I doubt you'll ever be able to get it to work, because almost all sites these days are partially or wholly generated on the server side, the page is only the result.
Some sites hide the information in memory and others get it dynamically through ajax for example, which means that simply trying to get the data by parsing the HTML will get zero data.
Another issue you should be aware of though, is that simply copying the data from generated websites may open yourself up to copyright issues.
You have to parse the html code and search for the part that you want and "throw" away the part that you do not need. This is more or less like bruteforcing and the code of the website should not change otherwise you are screwed. So you have to write the parser by hand with this method. But maybe there is a atom or rss feed and you can parse this one. This will be much more easier and you are not depending on the website layout because the rss/atom feed is just about the data. For parsing rss you could try out NSXMLParser.
And then you have to make a valid html page out of the data and present it in the UIWebView

Reduce the HTTP Requests of 1000 images?

I know this question might sound a little bit crazy, but I tough that maybe someone could come up with a smart idea:
Imagine you have 1000 thumbnail images on a single HTML page.
The image size is about 5-10 kb.
Is there a way to load all images in a single request? Somehow zip all images into a single file…
Or do you have any other suggestions in the subject?
Other options I already know of:
CSS sprites
Lazy load
Set Expire headers
Downloads images across different hostnames
There are only two other options I can think of given your situation:
Use the "data:" protocol and echo a base64 encoded version of your thumbnails directly into the HTML page. I would not recommend this since you cannot then cache those images on the users browser.
Use HTML5's Web Storage to store all the images as records with the base64 encoded image data stored as BLOBs in a column. Once the database has downloaded to the users machine, use Javascript to loop through all the records and create the thumbnails on the page dynamically using something like jQuery. With this option you would need to wait till the entire database was done downloading on the end users browser, and they will need a fairly modern browser.
I think your best bet is a combination of lazy loading, caching with expires headers and serving images from multiple hostnames.
If the images can be grouped logically, CSS sprites may also work for you in addition to everything above. For example, if your thumbnails are for images uploaded on a certain day...you may be able to create a single file for each day which could then be cached on the users browser.
This is done by using what's called a CSS sprite; a single image with all the other images inside it, with the particular part that's wanted in the html selected by css.
See one tutorial at http://css-tricks.com/css-sprites
It sounds like you want something like SPDY's server push. When the client requests the HTML page (or the first image), SPDY allows the server to push the other resources without waiting for more requests.
Of course, this is still experimental.
You could try the montage command of imagemagick to create a single image.

Resources