How to serve static profile images in node - image

This is really more of a "using what method" than a "how-to" question. I am creating a site in NodeJS with Express. So, each user has the ability to upload a profile picture, and my concern is how to route requests for these images. A couple of questions I have are:
Can I use express.static() to serve a default file if a valid one isn't specified? If not, am I going to have to specify a GET route for /img/profileand handle the FS querying there?
How can I find the correct image if multiple file extensions are allowed? (I originally just removed the file extension and they appeared in img tags anyway, is that okay?)
I am currently naming all pictures after their user's name. Looking ahead into the future (for apps I may have to scale), what are normal naming conventions for static user content? Are most stored with a UUID referencing the content in the database?
What else should I take into consideration that I may not have accounted for yet?

First question:
At present, I'd recommend storing your images in a predictable location that can be inferred from some combination of columns or fields in your database entries. One of those fields or columns would be a filename (accounts for different extensions). Then, if they haven't uploaded an image, you just lay down in your view code a reference to the generic "has not set an image" file.
express.static obviously can server static files, but it currently doesn't have a way to serve some other file if the one you wanted isn't there. Because this sounded like fun, I made some modifications to static to support what you request and submitted a couple of pull requests (the feature touched 2 different modules):
In send: https://github.com/visionmedia/send/pull/33
In connect: https://github.com/senchalabs/connect/pull/999
I don't know if those will get included in the project, but if you want to see my forks that have these changes, they are here:
https://github.com/bigohstudios/send
https://github.com/bigohstudios/connect
If this went through, you would mount a static at the root of your profile image files:
app.use(static('<profile image files root>', { fallback: 'anon.jpg'}))
Second question
I generally store the extension in my DB, then when I load the image, I have the correct extension to put into the src attribute on the img tag.
Third question
If you can guarantee unique names, then using those would work. I prefer using the DB id or a UUID as you suggest. It's less intuitive when scanning all the image uploads, but I rarely find myself doing that. I'm usually hunting for a specific image, and I can look up the identifier for that as needed.
Fourth question
You may end up storing the static content outside your app server (e.g. on S3). If that happens, then of course static won't help you.

Related

Extracting image dimensions in the background with Shrine

I have set up direct uploads to S3 with Shrine. This works great. Among others, I have the following plugins enabled:
Shrine.plugin :backgrounding
Shrine.plugin :store_dimensions
Shrine.plugin :restore_cached_data
Correct me if I'm wrong but image dimensions extraction appears to be done synchronously. If I let the user bulk upload images via Uppy and then persist them all, this seems to be taking a long time.
What I'd like to do is perform image dimensions extraction asynchronously - I don't need the dimensions available for the cached file. If possible, I'd like to do that in the background when the file gets promoted to the store. Is there a way to do it?
The way I got this to work is by making use of :refresh_metadata plugin, instead of :restore_cached_data which I used originally. Thanks to Janko for pointing me in the right direction.
Reading into the source code provided some useful insights. :store_dimensions plugin by itself doesn't extract dimensions - it adds width and height to the metadata hash so that when Shrine's base class requests metadata, they get extracted too.
By using :restore_cached_data, this was being done on every assignment. :restore_cached_data uses :refresh_metadata internally so we can use that knowledge to only call it when the file is promoted to the store.
I have :backgrounding and :store_dimensions set up in the initializer so the final uploader can be simplified to this:
class ImageUploader < Shrine
plugin :refresh_metadata
plugin :processing
process(:store) do |io, context|
io.refresh_metadata!(context)
io
end
end
This way persisting data we get from Uppy is super fast and we let the background job extract dimensions when the file is promoted to the store, so they can be used later.
Finally, should you have questions related to Shrine, I highly recommend its dedicated Google Group. Kudos to Janko for not only creating an amazing piece of software (seriously, go read the source), but also for his dedication to supporting the community.

How to Get FHIR Photo for Patient from a URL

Consider the FHIR Patient data at http://spark.furore.com/fhir/Patient/f201.
How can I get the photo object referenced therein at URL "binary/#f006"??
I would have thought an HTTP GET on http://spark.furore.com/fhir/binary/#f006 would have done it, but alas...
the data there is wrong. Your conversion to the get was correct, but you ended up with a wrong URL because the reference is wrong in the first place.
It should say: url="Binary/f006" which would equate to a get of http://spark.furore.com/fhir/Binary/f006. That doesn't work either, which is another error in the way things are defined.
See http://gforge.hl7.org/gf/project/fhir/tracker/?action=TrackerItemEdit&tracker_item_id=6107 for follow ups
Yes, this reference is outdated, and we are not distributing Binaries currently as part of the examples in the FHIR specification. Our server Spark loads the examples from the specification when we initialize the database, hence the images are not there.
For now, I have uploaded the correct image to Binary/f006 and have updated the link in Patient/f201, so things should work now. When we re-initialize the database (we don't do this often), these changes will be reversed, but a simple PUT to Binary/f006 and an update of Patient/f201 will fix this of course.

How can I get a list of all CSGO items including skin name, quality and rarity?

I'm not looking for details of a specific player inventory, but a list of all items for CSGO. What I want is details of the weapons in particular, but including skin name information and rarity.
To make it easier to explain this site has the information I need, except rarity.
http://csgo.steamanalyst.com/list.php
By using the following api url I can get weapon model names but not skin names (ie. "Zirka")
http://api.steampowered.com/IEconItems_730/GetSchema/v0002/?key={YOUR_API_KEY}
I haven't found anything regarding skins in Steam Web Api.
Lists of all skins as well as rarity and corresponding weapons are in "paint_kits", "paint_kits_rarity" and "item_sets" sections of /csgo/scripts/items/items_game.txt file.
As for their correct names, those are in /csgo/resource/csgo_YOUR_LANGUAGE.txt. Looking like that
"PaintKit_so_red_Tag" "Candy Apple"
Won't be hard to make php or python script to get all of it and put it in a database for ease of use.
For skins images you could get weapon and skin name from the above, and do a foreach curl loop to get content from div with "market_listing_largeimage" class using for example simple_html_dom.php, from url http://steamcommunity.com/market/listings/730/{ITEM_NAME}%20%7C%20{SKIN_NAME}%20%28{USAGE_THINGY Ex. Well-Worn}%29
Just remember to replace all spaces going to the url with %20 but that depends on what you use to get the page. You could do a foreach on the usage thingy since some weapons don't have some variants on the market, curl could return wrong page. Nothing that a simple if+foreach couldn't fix.
Also do it only after skins update if overused you could get blocked from valve website for spamming. You could also use SteamWebApi and game news to check for new versions and update it automatically then. Just use your imagination and google.

Implementing resource list in WP7

I am porting a JAVA game to WP7. We have lots of images in our game and for loading them in JAVA use a function something like this "Resources.getImage(IMG_BULLETS);" where IMG_BULLETS is ID(an int) of the image.
But in WP7 we have to pass the path(a string) of image in order to load that.
Now my question is :
How to achieve a int-String mapping? so that I dont have to manually change the Id into path.
One possible solution comes in my mind is to have a .txt file having image path and its Id and parse that. But I am sure their is much better solution for this.
Note : we also have a multi-level folder structure for images and other files.
If you really want to refer to resources by int, you are going to have to map them some how to their path. As far as I know, there is no way to crawl your assets, and even if you could, i some how doubt you will get the same index order and you would have to redo your enum.
There are going to be a few hurdles you hit with trying to port and code changes. Another one, (one you will still have even with a txt file work around) will be that the contentManager.Load takes a type, eg, contentManager.Load<Texture2D>('path') returning a Texture2D.
One option would be to create your own singleton 'Resources' class that has get methods that take int to get the appropriate asset, however you will still need a mapping via xml or txt file of somekind. However this will require all your assets being loaded from the start which are more problems of their own (90mb memory limit and really long load time).
My advice would be look at the game development section of the App Hub and have a look at the game state example to help you see how you might be able to structure your game to work well with XNA.

Sitecore global url to specific url

Currently I am facing the following problem:
A website, which I have to make for a company, has different locations. But the content of a few pages is for all locations the same. Now I have created a global folder with the items for all the locations. But now I am facing the following problem: when accessing the global items from the website of a specific location I get the global url. But what I want is that the specific location url remains the same structure, for example:
Now it is www.url.com/global/subfolder/itemname
And what I want is www.url.com/location1/subfolder/itemname
Does anybody have any solution(s)/suggestion(s) for this problem?
Does anybody also have a solution for creating a menu to insert these global items but also to insert the location specific items?
Some more information about my Sitecore content structure
Global: contains the global items for alle locations
Corporate: the corporate website of the company
Location1: the website of location1
Location2: the website of location2
Adam Weber was right, cloning is your best solution:
Create your Global section, with all the child items you need
For each of your local sections, clone the global section and place it where you'd like it to appear within your local menu
If I understand you correctly, this is what I'd do. It might not be the prettiest solution. But it'll work.
You have your "data" items in /global/subfolder/itemname
then just create some templates, which are "dummy" pages, that only contain a link to the global item (and perhaps the few fields that could differ (perhaps contact email for the specifik location).
Then you make a sublayout that bascially jsut gets the referenced item and uses that instead of Sitecore.Context.Item.
Then create an instance of the "dummy" template in /location1/subfolder/itemname and reference it to /global/subfolder/itemname
That way you URLs will be correct and the data will be the same.
Another and probably smarter solution (if you have enabled proxies) is to create a proxy that takes
/global/subfolder/itemname as source and points to /location1/subfolder/ as target (or you could take /global/subfolder and check "include children".
Here is a Guide on how to use proxies in 5.3:
http://sdn.sitecore.net/Articles/Administration/Using%20Proxy%20Items%20in%205,-d-,3.aspx

Resources