WebApi icon indicating copy to clipboard operation
WebApi copied to clipboard

[Feature] Add Stream Support to WebApi

Open liqian19891011 opened this issue 11 years ago • 15 comments

Add contents for Stream support in OData V4 on odata.github.io/WebApi.

We have related questions on StackOverflow

liqian19891011 avatar May 05 '15 07:05 liqian19891011

Consider to support named stream (aka stream property) or media link entry (i.e., media entry) If named stream, we need to change OData entry serializer.

public class CustomODataEntityTypeSerializer : ODataEntityTypeSerializer
{
    public CustomODataEntityTypeSerializer(IEdmEntityTypeReference entityType, ODataSerializerProvider serializerProvider)
        : base(entityType, serializerProvider)
    {
    }

    public override ODataProperty CreateStructuralProperty(IEdmStructuralProperty structuralProperty, object entityInstance, ODataSerializerContext writeContext)
    {
        if (structuralProperty.Type.IsStream())
        {
            return new ODataProperty { Name = structuralProperty.Name, Value = new ODataStreamReferenceValue { ReadLink = new Uri("http://image") } };
        }

        return base.CreateStructuralProperty(structuralProperty, entityInstance, writeContext);
    }
}

If media link entry, we need to create an entity type with HasStream set to true in OData v4. E.g., use this ctor:

public EdmEntityType(string namespaceName, string name, IEdmEntityType baseType, bool isAbstract, bool isOpen, bool hasStream);

The change is in model builder.

congysu avatar May 12 '15 09:05 congysu

thanks @congysu Is this issue accepted for next release of libraries?

For interim do you have any suggestion on how we can go ahead and add the stream support.

sammym1982 avatar May 27 '15 02:05 sammym1982

@sammym1982 The related issue is https://github.com/OData/WebApi/issues/149. Can start from a blog: http://blogs.msdn.com/b/mrtechnocal/archive/2013/12/31/10462258.aspx, although it is for OData v3 Web API.

congysu avatar Jun 01 '15 05:06 congysu

@congysu

I do tried porting that code to V4 but the issue as I mentioned in my original post on stackoverflow is there is currently no way available to mark an entity as HasStream = true. The original IEdmModel.SetHasDefaultStream seems like no longer available.

Model we have is as followos:

Entity: Incident NavigationProperties Collection: Attachments

Therefore We want all our attachment posts to happen as below:

POST: http://foo.com/incidents(1L)/Attachments

sammym1982 avatar Jun 01 '15 17:06 sammym1982

@sammym1982 I have a pr #379 , expose the HasStream Property, which is helpful to your customize, would you help to review?

VikingsFan avatar Jun 08 '15 06:06 VikingsFan

We shall port the sample http://blogs.msdn.com/b/mrtechnocal/archive/2013/12/31/10462258.aspx to v4.

congysu avatar Jul 09 '15 06:07 congysu

Guys any news on this. We are working with OData v 4.0 and now we are completely stuck, which is very disappointing. Can you implement in the model builder this extension and release a fixture over Nuget ASAP?

raffaeu avatar Jul 25 '16 17:07 raffaeu

Pinging this as 'still relevant' in case anyone is listening... :)

ivanko2000 avatar Jan 12 '17 00:01 ivanko2000

Like @ivanko2000, media resources recently became relevant to my interests/requirements as well.

lsuarez5280 avatar Jan 24 '17 16:01 lsuarez5280

We also have OData Services V4 running, and cannot integrate former streaming. Waiting for the implementation of streaming support in OData V4, please implement ASAP

GerdN67 avatar Dec 14 '17 10:12 GerdN67

I'm not sure if this is what they're after, but I do have streams working in my code: https://stackoverflow.com/a/48851615

kevin-osborne avatar Feb 18 '18 12:02 kevin-osborne

@madansr7 please prioritize.

biaol-odata avatar Aug 08 '18 21:08 biaol-odata

Any intention to release this yet ? We are in year 4 since this was raised after all.

TehWardy avatar Apr 11 '19 08:04 TehWardy

Would be very glad to hear if this issue will be fixed or not.

SiberaIndustries avatar Aug 01 '19 09:08 SiberaIndustries

Closed since it appears the issue was addressed by the linked PR. If the issue still exists in the latest versions of the library, kindly open a new issue.

habbes avatar Mar 01 '22 09:03 habbes