Copied to clipboard

Flag this post as spam?

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


  • Alex Skrypnyk 6148 posts 24077 karma points MVP 8x admin c-trib
    Oct 15, 2014 @ 16:31
    Alex Skrypnyk
    0

    Upload Images to the 'Upload' DataType from code

    Hi,

    I want some suggestion how to do upload Images to the 'Upload' DataType from code. What is the best way ?

    Without creating node in Media section. It would be great.

    Thanks

  • Danny Blatant 91 posts 358 karma points
    Oct 17, 2014 @ 16:34
    Danny Blatant
    1

    Hi Alex,

    I'm not sure what you're trying to achieve here, as the Upload DataType itself creates the Media Node...

    If you just wanted to add an upload to the Media library via code you can use MediaService.CreateMedia

    If however you're literally looking for a primitive "Upload a file to ~/here/" type of thing, how about good old plain C#, something like this:

    http://support.microsoft.com/kb/323246

    Of course it deals with an Upload form object however the handling code should be just what you need?

    I'd recommend using the MediaService though, particularly if your meaning to upload to the /media/ directory, as then your upload is available via the content editors...

    Hope this help!

    Danny "Blatant"

  • Alex Skrypnyk 6148 posts 24077 karma points MVP 8x admin c-trib
    Oct 20, 2014 @ 16:18
    Alex Skrypnyk
    0

    Thanks Danny,

    I just wanted to know how do do uploading image as does it Umbraco but from code. Not media Uploading, I want to upload images as upload picker.

    Thanks

  • Danny Blatant 91 posts 358 karma points
    Oct 20, 2014 @ 16:31
    Danny Blatant
    0

    Hi Alex,

    Is this Umbraco 7??

    I think there's a little confusion here, as in Umbraco 7 we have a Media Picker AND and Upload field. However both of these upload to the Media library.

    I believe the Media Picker adds the picker call out where you can upload new images ect and pick one by clicking.

    However with the Upload Data Type (I've just tried it on my local working copy) simply exposes the upload button for you. However once you upload a file it is added to the Media folder anyway, you just lose the picker pop out and Media Library control.

    If you want to see exactly how the Upload DataType does it, check out the Umbraco source for it here :

    https://github.com/umbraco/Umbraco-CMS/blob/7.2.0/src/umbraco.editorControls/uploadfield/uploadField.cs

    Lines 30 to 33 show you how to get a reference to the FileManager and stuff, lines 120 to 149 detail the Save function, which will save your file. You should be able to get what you need from that right?

    Let me know if that helps at all!

    Danny "Blatant"

  • Alex Skrypnyk 6148 posts 24077 karma points MVP 8x admin c-trib
    Oct 20, 2014 @ 17:14
    Alex Skrypnyk
    0

    Danny, thank you very much, yes this is Umbraco 7. I thought about upload control because, it doesn't create Media item in Media section. Is it more lightweight for database maybe ?

    Thanks

  • Danny Blatant 91 posts 358 karma points
    Oct 20, 2014 @ 17:21
    Danny Blatant
    1

    It certainly is! AFAIK!!! (cue umbraco Guru telling me we're wrong...)

    I'll be honest as I deal 95% of the time with managed media, I never even looked into the Upload control until you asked. But I agree with your supposition that there may be much less DB overhead with this method, however thats not to say there is none, the media path is still stored somewhere!

    Also the DB is quite efficient what with the PetaPoco methods but I think one of the main advantages is the Upload contrl leaves it to you to impliment the file handling (don't forget to check the file with XSS or something!) instead of helping you.

    It also occurs to me that I've never tried the Media Picker and Library with non image files. If the library can't handle these (thumbnails being an obvious reason why) then it's a much better option for document uploading... but as I say I've not dug deep yet :)

    If you got what you need from the source, feel free to mark as a solution! It helps forum users find good answers when searching (and I could do with a fe more Karma, what with the amount of questions I ask!!)

    Kind Regards,

    Danny "Blatant"

  • Alex Skrypnyk 6148 posts 24077 karma points MVP 8x admin c-trib
    Oct 21, 2014 @ 20:04
    Alex Skrypnyk
    0

    So Danny, you think that better is using Media ? How to do uploading from code, it's not crear.

Please Sign in or register to post replies

Write your reply to:

Draft