I'm developing a package for the new Umbraco 11 version, In there I need to create media and get its URL using byte stream. Seems it's a bit different from the older version such as version 7/8. Can anybody suggest me way of doing it or clear documentation or an article that I can get some support?
But I need to set the value for the media URL. If I parse only the first two parameters it only creates a dummy file in Umbraco media, not the actual image I added.
you are not passing in the correct values which is why it is defaulting to the wrong overload, you need to pass ALL the correct values as shown in the example and in my post above, one of those is the stream, you can't just pass in 2 values like you are attempting.
Hi Huw,
I was trying to implement this function in the separate class library and it has some other functions as well. After moving the saving function to a separate class this is working fine.
Thanks a lot for your support, Now I'm trying to identify what is the actual reason for not working with the same class previously added. I will update the thread after I found the reason. Thanks again.
I had the exact same issue and for me the problem was that I was passing a Task<Stream> instead of a Stream as the last argument. Still haven't been able to test this properly, so I'll check back if I've spoken too soon.
Umbraco 11 - Create media from Stream
I'm developing a package for the new Umbraco 11 version, In there I need to create media and get its URL using byte stream. Seems it's a bit different from the older version such as version 7/8. Can anybody suggest me way of doing it or clear documentation or an article that I can get some support?
Hi Eranga,
Without knowing what method you are currently using, do the new docs not help?
https://docs.umbraco.com/umbraco-cms/reference/management/services/mediaservice
In Umbraco 7, I'm using the following method and its working fine
This is the one I'm trying to use on Umbraco version 11
This just create dummy file on media section but content empty as below image
Did you try the code example in the link I posted? (it does not appear to be the same code as you are currently trying)
Hi Huw, Yes I tried But SetValue Method signature bit different in Umbraco 11 than mentioned in the documentation it accepts only these parameters.
But I need to set the value for the media URL. If I parse only the first two parameters it only creates a dummy file in Umbraco media, not the actual image I added.
you don't appear to be passing the stream in the setvalue call (last value passed in the method, after filename.
Yes, but about method signature is different. It doesn't accept stream
Not sure what you are doing then, as the SetValue method does accept a stream in Umbraco 11, exactly as shown in the example from the documentation.
There are 2 overloads for that method
Thanks, but I can't see two overloads in IContentBase Interface. That is the issue
Please correct me if you see I missed anything. Also if you need I can show you my full method
Full method would help since you should have an Imedia object not Icontentbase
Hi Huw, I'm creating IMedia object. Please check my method
you are not passing in the correct values which is why it is defaulting to the wrong overload, you need to pass ALL the correct values as shown in the example and in my post above, one of those is the stream, you can't just pass in 2 values like you are attempting.
Method signature for SetValue
Parsed parameters the way you mentioned in the previous reply(Please see attached image) but now it's giving an error saying
remove _contentBase from you method call, it is passed explicitly because it is an extension method, hence the this in the signature definition.
so call it as below.
Thanks Huw , I had tried this but it still says
Did you try this previously Umbraco version 11?
Yes, I have tested it in Umbraco v11, here is a simple controller class which I tested with, it succesfully creates a media file in the backoffice.
Thanks. Let me try this on a sample project and let you know the results
Hi Huw, I was trying to implement this function in the separate class library and it has some other functions as well. After moving the saving function to a separate class this is working fine.
Thanks a lot for your support, Now I'm trying to identify what is the actual reason for not working with the same class previously added. I will update the thread after I found the reason. Thanks again.
Glad you got it working.
I had the exact same issue and for me the problem was that I was passing a
Task<Stream>
instead of aStream
as the last argument. Still haven't been able to test this properly, so I'll check back if I've spoken too soon.is working on a reply...