Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Ulrik Nedergaard 44 posts 175 karma points
    Sep 28, 2011 @ 11:39
    Ulrik Nedergaard
    0

    Put external image into Upload-datatype

    Hi

    I'm going to convert some sites to Umbraco and I intend to create a function that loops through for instance a product table, and put the content into a node in Umbraco. Done by user-control or some seperat .aspx file.

    My question is : How do I take an image from the old site - lets say "http://www.website.com/images/myimage.jpg" - and save it in an upload-datatype?

    I found this code for saving image - but I guess that won't make Umbraco define where it's archived :(

    Dim client As New WebClient
    Dim strURL As String = "http://www.website.com/images/myimage.jpg"
    Dim strFilename As String = Server.MapPath("myimage.jpg")
    client.DownloadFile(strURL, strFilename)
  • Ulrik Nedergaard 44 posts 175 karma points
    Nov 04, 2011 @ 13:40
    Ulrik Nedergaard
    0

    .... Anyone ? :)

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Nov 04, 2011 @ 13:57
    Tom Fulton
    0

    Hi Ulrik,

    The files you upload with the Upload datatype are stored in /media/<property id of current upload field/file.ext.  However, there's no harm in adding them to a /media/products/ folder or something similar if there are no naming conflicts.  So once you download the image you can simply set the value of the upload field to the path of your file.

    You would do this using the Document API.  In C# something like:

    Document d = new Document(1234);
    d.getProperty("yourUploadField").Value = "/media/products/" + yourFileName;
    d.Publish();
    umbraco.library.UpdateDocumentCache(d.id);

    Note if you then upload a new file manually in the UI it will then store the new file in the proper /media/.../ location, but again there's no harm either way.

    Also, you should look into CMSImport as it can probably help you out here and save you from writing any code :) It can handle importing from DB's and into many fields like upload and media pickers.

    -Tom

Please Sign in or register to post replies

Write your reply to:

Draft