Copied to clipboard

Flag this post as spam?

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


  • Peter Alcock 113 posts 176 karma points
    Mar 01, 2013 @ 10:57
    Peter Alcock
    0

    Usercontrol upload media

    Hi all again!

    Trying to get my front end usercontrol to upload an image which saves in the media, got as far as getting it to create an image in the media section which on the umbracoFile field shows the image name that was uploaded however there is no thumbnail, size, width, height etc and cannot display the image on the website.

    Any ideas? have pasted my code below

    Thanks

    usercontrol

     <asp:FileUpload ID="FileUpload1" runat="server" />

           <asp:Button ID="Submit" runat="server" Text="Upload"  style="height: 26px" OnClick="Submit_Click"  />

    codebehind

     protected void Submit_Click(object sender, EventArgs e)

        {

            //my document type is named Foto

            MediaType foto = MediaType.GetByAlias("Image");

            //Making a new photo

            Media newPhoto = Media.MakeNew("chicken", foto, User.GetUser(0), 1234);

            //photoUp is my upload property in my Foto document type

            newPhoto.getProperty("umbracoFile").Value = FileUpload1.PostedFile.FileName;

        }

  • gary 385 posts 916 karma points
    Mar 01, 2013 @ 11:27
    gary
    0

    Hi Pete

    On the MediaType you have created in the Settings Section, do you have the labels for size, width etc? If the image is in the Media Section, then these Umbraco properties should exist, but if they are not part of the Media Type, you will not see them.

    Little confused over document type Foto, then MediaType Image, not sure if you have created a new MediaType called Foto, or are trying to uplad into an Umbraco property of image?

     

  • Peter Alcock 113 posts 176 karma points
    Mar 01, 2013 @ 11:31
    Peter Alcock
    0

    Hi Gary thanks for getting back to me!

    Sorry the MEdiaType is the standard 'Image' the 'foto' is just a variable i think which equals the #image# mediatype, it's a bit of code i found online but had to alter to work with the standard image mediatype if that makes sense!

    When the image is uploaded and in the media section the only field that has a value is the umbracoFile field but instead of a thumbnail it just shows 'media/081.jpg'

    Hope that makes more sense! more than open to a new way of doing it! have tried a number of different codes found online but this is the only one i can get to build

    Cheers

  • gary 385 posts 916 karma points
    Mar 01, 2013 @ 11:37
    gary
    0

    Hi Pete

    Just a quick thought before taking it apart too much, what Version of Umbraco are you using, the reason I ask is that this was happening with DAMP in a particular version, would need to look which one, ie it was all uploading fine, but the properties were not being displayed (just as you sday). It was resolved, so maybe it would be worth checking that before trying to "fix" what isn't broken.

    Let me know the version and see what I can find

    G

     

  • Peter Alcock 113 posts 176 karma points
    Mar 01, 2013 @ 11:41
    Peter Alcock
    0

    Hiya,

    Im using 4.11.3, many thanks for your help Gary this has been a right nightmare for the last few days heh heh!

    Cheers

    Pete

  • gary 385 posts 916 karma points
    Mar 01, 2013 @ 12:40
    gary
    0

    Hi Pete

    Sorry, have been looking, but also for a solution at the same time. Ok, just checked your code again, it doesn't actually upload the image?, so hence only the "name" exists.

    I've not done this myself, but would it not be easier to use the current Upload control in Umbraco for your user control? So use the button to fire the upload?

    Ok, think this is the route I would take, if your button fires media.ascx file in Umbraco>Controls>Create, you will get the use of the code behind media.ascx.cs, in other words, let Umbraco handle it. Like yourself, I'm not overly experienced in this area, so would be looking for the "safest" route possible. Or if you want something different, create the user control you want and then use the Umbraco code behind. Or customize what already exists.

    This would also make everything work with your current version.

    Unless of course, someone has a better offer for you.

    Sorry not complete solution, but hope it can help.

    Regards G

  • Peter Alcock 113 posts 176 karma points
    Mar 01, 2013 @ 12:45
    Peter Alcock
    0

    Hi Gary,

    Thanks for that, I see what you mean and did think about it as well but not sure how i can use the upload control you use in the media section in a seperate usercontrol if that makes sense?

    From what i can tell it's editMedia.aspx which contains all the code for uploading new media in the media section, any ideas how to reference it in a seperate user control which is a ascx?

    Thanks again mate

    Pete

  • gary 385 posts 916 karma points
    Mar 01, 2013 @ 12:55
    gary
    0

    Hi

    Kinda like Stevie Wonder leading Ray Charles, but we might get there in the end?

    Ok, guess what? In Controls>Images there is a UploadMediaImage.ascx file, now I couldn't swear by it, but I think it may do what is says on the tin? This also calls the js files etc that are needed to "lift" the image.

    So, what we need to find is the event that opens that upload "pop-up" when you would create an image in "normal" circumstances, ie the create   delete that sits on the docType. If we find that, just add it to the button to fire it up.

    Will dig in that now to see if I can find it - surely between us we can do this?

    G

     

  • Peter Alcock 113 posts 176 karma points
    Mar 01, 2013 @ 12:59
    Peter Alcock
    0

    Hi Gary,

    See two heads are better than one, especialy when one head doesn't know much of what he's doing haha! That's great ill have a play around too and see what we can come up with. your a star mate.

    Thanks

    Pete

  • gary 385 posts 916 karma points
    Mar 01, 2013 @ 13:08
    gary
    0

    Pete

    Can you create a normal media upload on a doctype? I have Damp on all my projects so am not getting what you need.

    If you right click> inspect Element you will see the code for firing the upload, it is in the <text/javascript>, if you can attach that to your button, or indeed find that js file. you can call that. Will look now

    G

  • gary 385 posts 916 karma points
    Mar 01, 2013 @ 13:13
    gary
    0

    Doh!!!!

    In the Controls>Images folder are two script files, it's one of them, probably UploadMediaImage.js (hmmm!!!). Activate that script from your button, stand back and contact Houston!!!

    So, Laurel and Hardy do Umbraco!

    Let me know how it goes - 

     

    G

     

  • Peter Alcock 113 posts 176 karma points
    Mar 01, 2013 @ 13:26
    Peter Alcock
    0

    Hi mate sounds positive heh heh!

    It makes sense what your saying but I'm a bit lost as to how to activate the script from my button etc (A right novice!) on my usercontrol i have the upload contol with submit button, so it's the submit click function that needs to fire the uploadmediaimage.js to upload the selected file im guessing!

    Any idea what the cs code would look like, sorry im a right pain i know heh heh trying to get there!

    Cheers 

    Pete

  • gary 385 posts 916 karma points
    Mar 01, 2013 @ 13:30
    gary
    0

    Hi

    I'm nearly there - just finding the right file, I'm hoping that you can just call the url from the button to get the pop-up, then all the code is in place. Just opened up 

    Umbraco/Dialogs/uploadImage.aspx but thats the backend, be back to you in a jiffy.

    Once we find the right file, then we can do the worrying about the other bit.:)

    g

     

  • gary 385 posts 916 karma points
    Mar 01, 2013 @ 14:15
    gary
    0

    Pete

    Ok, this will "work" from your button call this page for now just <a href>  /umbraco/Dialogs/uploadImage.aspx. Any media uploader is a version of this file. It has everything you need. ie populates the name then will update all fields for Umbraco.

    But, it ain't very pretty in its current state - if you can prove it works on your system then we can go about pulling it apart and including the "necessary" parts in the file you have, or styling as it is.

    Have to go out now, but soon as I am back will help some more, if you get it to work that is!

    Hope it helps mate G

  • Peter Alcock 113 posts 176 karma points
    Mar 01, 2013 @ 14:32
    Peter Alcock
    0

    Hiya,

    Right ok i've got as far as linking the uploadimage.aspx in the usercontrol which works to upload an image, the next step then is to make it auto populate the name and where it's saved to if thats possible!

    Ive done basicaly the same thing for creating a document(profile page), a member logs in and can create a profile(document type profile) and it auto names it the same as the members username using 'Page.User.Identity.Name', would ideally need the same to happen with the media and to specifiy the folder to be saved under again hope that makes sense!

    Getting there though, thanks for all the help so far it's been a right learning curve!

    Thanks

  • gary 385 posts 916 karma points
    Mar 01, 2013 @ 16:46
    gary
    0

    Hi

    Just back - where have you got to?

    G

  • Peter Alcock 113 posts 176 karma points
    Mar 01, 2013 @ 16:52
    Peter Alcock
    0

    Hi Gary, 

    Still at the point as my above post, media uploader is on there and works but do need to get it to set a fixed name and aprent folder, would it help for you too see the webpage the usercontrol is on? if so let me know your email address and ill send it to you and a login for the page (uses membership)

    Cheers again

  • gary 385 posts 916 karma points
    Mar 01, 2013 @ 16:57
    gary
    0

    Hi

    Could be easier, can be reached via    [email protected].

    Cheers G

  • Peter Alcock 113 posts 176 karma points
    Mar 04, 2013 @ 17:30
    Peter Alcock
    0

    Hi all,

    Still need a bit of help with this one, i have got as far as being able to upload an image fine by referencing the umbraco/Dialogs/uploadImage.aspx and preseting the name and location which works great.

    The only flaw is you need to be logged into umbraco to be able to use it even from a frontend page, is there anyway to overwrite this? so in this case a member logs into their page and can the form to upload an image, at the moment the page redirects to /umbraco/login.aspx?redir=%2fumbraco%2fDialogs%2fuploadImage.aspx when the member logs in.

    Thanks

    Pete

Please Sign in or register to post replies

Write your reply to:

Draft