Copied to clipboard

Flag this post as spam?

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


  • rasb 162 posts 218 karma points
    Mar 19, 2010 @ 20:59
    rasb
    0

    Member upload photo - Best practice

    Hi guys,

    I am setting up membership for a site, and would like to give the members the possibility to upload one or more pictures to their profile.

    What is the best practice regarding this? I have created a control that allows the members to edit their profile, but I am not sure I wish to include a Media Picker in that profile editor.

    How should I approach this?

    Thanks,
    RasB

  • Douglas Robar 3570 posts 4670 karma points MVP 6x admin c-trib
    Mar 19, 2010 @ 23:03
    Douglas Robar
    0

    Why not use an upload control? Have I missed something important?

    cheers,
    doug.

  • Douglas Robar 3570 posts 4670 karma points MVP 6x admin c-trib
    Mar 19, 2010 @ 23:04
    Douglas Robar
    0

    That is to day, a property on your membertype of type 'upload'.

    They could upload anything (pdf, swf, etc.) so you'd want to do some checking that it is really an image before you try to display it.

    cheers,
    doug.

  • rasb 162 posts 218 karma points
    Mar 19, 2010 @ 23:37
    rasb
    0

    Hi Doug,

    You haven't missed anything ;-) I think I have.

    Just to spell it out... if I add an upload control to the member type, and use the umbraco editor controls to render the members "edit profile" page, then I need to save the image somewhere, and I guess that is in the media section. When I use the Edit Member page in the umbraco backend, it just uploads the image to the media section, but it isn't displayed anywhere.

    Where is the value saved? And is there example code to handle that upload? I have just created a user control that looks at the member type and displays the controls on there. I have yet to handle all specific controls... upload being one of them.

    Thanks,
    RasB

  • rasb 162 posts 218 karma points
    Mar 20, 2010 @ 01:42
    rasb
    0

     

     

    Hi Doug,

    When I try to upload an image using the uploadField, it just goes wrong. I get this exception:

    Invalid attempt to read when no data is present.

    Stack Trace: 

     

    [InvalidOperationException: Invalid attempt to read when no data is present.]
       System.Data.SqlClient.SqlDataReader.ReadColumn(Int32 i, Boolean setTimeout) +778859
       System.Data.SqlClient.SqlDataReader.GetGuid(Int32 i) +29
       umbraco.DataLayer.RecordsReaderAdapter`1.GetGuid(String fieldName) in d:\TeamCity\buildAgent\work\7380c184e9fcd3ea\umbraco\datalayer\RecordsReaderAdapter.cs:263
       umbraco.cms.businesslogic.datatype.DefaultData.get_Version() +135
       umbraco.editorControls.uploadField.Save() +214
       TestSite.MemberProfile.SaveControlValue(Control c, Member m, String prop) in C:\Development\Test\TestSite\MemberProfile.ascx.cs:298
       TestSite.MemberProfile.saveBtn_Click(Object sender, EventArgs e) in C:\Development\ Test\TestSite\MemberProfile.ascx.cs:238
    System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565

     


    The code I use to upload is pretty simple, and something I got from looking at the Umbraco source code on Codeplex. I am not sure it is correct though:

    uploadField uf = ((uploadField)ctrl);
    if (uf.PostedFile.ContentLength > 0)
      uf.Save();

    I think this goes wrong when it tries to delete the existing file. But I am not sure.

    Thanks,
    RasB

     

     

  • rasb 162 posts 218 karma points
    Mar 20, 2010 @ 19:47
    rasb
    0

    Ok... cleaning up some other code seems to have made this work. It works now in any case, without me touching the code ;-)

    So where does this end up? I cannot browse the image in the media section.

    /RasB

  • Stephan Lonntorp 195 posts 212 karma points
    Mar 20, 2010 @ 20:46
    Stephan Lonntorp
    0

    The upload datatype stores files in /media folder on disk, but doesn't create a media item, so you can't see it there. You could however easily create the media object yourself programmatically, but it wouldn't be linked to the member. If you want your member's images tored in the media section, I'd create a media item programmatically, and link that to the member instead.

     

     

Please Sign in or register to post replies

Write your reply to:

Draft