locked
Share images across 3 sites RRS feed

  • Question

  • User-1526035670 posted
    Hi

    Could someone guide me with the appropriate approach to share images across multiple sites.

    Site 1 (http://admin.abc.com) is an admin site forcing users to log in and upload images. Currently uploaded to the images folder on this site.
    Site 2 (http://abc.com) is displaying images by using code and referencing the images folder from admin site.
    Site 3 (http://different.com) I need to display images from the above site(s). I'm in process of writing a web service but not sure how I could reference the images I require?

    All 3 sites are on the same server.

    Thanks in advance
    Thursday, March 5, 2020 8:06 PM

Answers

  • User409696431 posted

    If the images are in a publicly available folder, simply link to them.  E.g, to see google's logo in your browser, go to https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png .  If you have not put security on the folder your images are in that prevents it, you'll be able to see your images the same way in your browser.

    In a page, make the address of your image the source of an image tag:

    <img src="https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png" >

    If the folder your images are in is not publically accessible, then you need to deal with the other options discussed.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, March 6, 2020 12:46 AM

All replies

  • User475983607 posted

    Pretty simple.  Pick one of the sites to host the image.  Then place the image in a folder.  Then the image will be available to whatever site you like.

    http://abc.com/images/mySharedImage.gif

    Thursday, March 5, 2020 8:14 PM
  • User-1526035670 posted
    Hi

    The current images folder is within site 1 which requires a user to be logged in) so from what you're saying I can leave the current uploading process as is but for site 3 I just hotlink to site 2 (site 2 is public) by using a fully qualified path to the images?
    Thursday, March 5, 2020 8:22 PM
  • User-1526035670 posted
    Is there a particular preferably free image handler your aware of? I may consider some chargeable ones
    Thursday, March 5, 2020 8:25 PM
  • User475983607 posted

    The current images folder is within site 1 which requires a user to be logged in) so from what you're saying I can leave the current uploading process as is but for site 3 I just hotlink to site 2 (site 2 is public) by using a fully qualified path to the images?

    I have no idea how your application works.  If the image is hosted in site 1, then linking to the image should work.  If the image is outside the hosted application, then you'll need to craft a handler, a page, or an action to return the image.  The handler, page, or action will allow anonymous access.

    Thursday, March 5, 2020 8:27 PM
  • User475983607 posted

    Is there a particular preferably free image handler your aware of? I may consider some chargeable ones

    This is pretty basic stuff and generally just a few lines of code but we need to know what kind of application site 1 is, Web Forms, MVC, Core, and where the images are stored.   

    Thursday, March 5, 2020 8:30 PM
  • User-1526035670 posted

    Web forms for this particular solution.

    MVC for future solutions.

    Images would be stored under the root directory
    Thursday, March 5, 2020 8:33 PM
  • User-1526035670 posted
    Hi

    The purpose is to upload an image in site 1.
    The image uploaded to site 1 is to display on site 2.
    Site 3 is completely separate to site 1 and 2.

    What I've done now is;
    When a user uploads an image in site 1, it saves to the directory on site 2.
    From what you're advising, I should now link to images from site 3 using a public URL to site 2?

    As I understand, when uploading images I can use directory paths as in c:\site\images\ to save the images but when displaying the images it must be in the format //(site)/images/.....

    If this sounds correct, I can mark this as a solution
    Thursday, March 5, 2020 9:22 PM
  • User475983607 posted

    JamieP1

    Hi

    The purpose is to upload an image in site 1.
    The image uploaded to site 1 is to display on site 2.
    Site 3 is completely separate to site 1 and 2.

    What I've done now is;
    When a user uploads an image in site 1, it saves to the directory on site 2.
    From what you're advising, I should now link to images from site 3 using a public URL to site 2?
    If this sounds correct, I can mark this as a solution.

    Again, if the image is hosted by the application, for example the image is in a folder within the application, then you can just link to the image.  Only ASP.NET file extensions, aspx, invoke the page life cycle and are secured by ASP.  An image file invokes IIS's static file handler and IIS just servers up the file.  That is, unless you did something to stop this default behavior.

    Thursday, March 5, 2020 9:28 PM
  • User-1526035670 posted
    I'll take that as the process I've listed above is correct as the image is under the application though NOW saving under the directory of a public facing website.

    As I understand, when uploading images I can use directory paths as in c:\site\images\ to save the images but when displaying the images it must be in the format //(site)/images/....??
    Thursday, March 5, 2020 9:42 PM
  • User753101303 posted

    Hi,

    You are using web forms or MVC ? Rather than using a direct http link to the image file, you'll give a link to an ashx handler or a MVC action that will fetch the image file from its physical location and that will return its content givving the browser exactly the same response than a direct access to the file.

    It's commonly used to have multiple machines with the same website and each site instance still gives access to the same database as well as the same files...

    Edit: if you prefer if you save images to c:\images, all sites on this machine could read files from this folder. If using a network share such as \\server\folder then all other server being granted access to the same file folder could serve files from this location.

    Or with later SQL Server versions storing files inside the database could be an option.

    The only difference is that as files are not directly stored at a location reachable from the internet, you'll have to write code that fetch image data from its storage location and send back this content to the browser.

    Thursday, March 5, 2020 9:52 PM
  • User-1526035670 posted
    Hi

    I've read I could either link via http as above or virtual directory. I'm not entirely sure how I would approach your proposed solution but if you don't mind giving some details on how to carry this out that would help.

    I'm using web forms for this particular client. What I have tried is saving the image using drive paths (c:/site/images) which is fine but displaying the images had become a little cumbersome if not mildly confusing.

    Many thanks
    Thursday, March 5, 2020 10:03 PM
  • User409696431 posted

    If the images are in a publicly available folder, simply link to them.  E.g, to see google's logo in your browser, go to https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png .  If you have not put security on the folder your images are in that prevents it, you'll be able to see your images the same way in your browser.

    In a page, make the address of your image the source of an image tag:

    <img src="https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png" >

    If the folder your images are in is not publically accessible, then you need to deal with the other options discussed.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, March 6, 2020 12:46 AM
  • User-1526035670 posted
    Hi all

    Thanks for your thoughts. I would have preferred an answer with an image handler/example but it seems I need to look into this further.
    Friday, March 6, 2020 7:58 PM
  • User475983607 posted

    Hi all

    Thanks for your thoughts. I would have preferred an answer with an image handler/example but it seems I need to look into this further.

    IMHO, you are making this more difficult than necessary.  Anyway, below is a handler where the file(s) are outside the hosted application.  I simply used Visual Studio to create a "Generic Handler".  Right click the project -> New -> Generic Handler.  Read the "file" querystring parameter and returning the image from C:\Images. 

    Imports System.Web
    Imports System.Web.Services
    
    Public Class ImageHandler
        Implements System.Web.IHttpHandler
    
        Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
            Dim file As String = "C:\Images\" & context.Request.QueryString("file")
            context.Response.ContentType = "image/jpeg"
            context.Response.WriteFile(file)
        End Sub
    
        ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
            Get
                Return False
            End Get
        End Property
    
    End Class

    Implementation

    https://localhost:44391/ImageHandler.ashx?file=strat.jpg


     

    Friday, March 6, 2020 10:19 PM