[ 
https://issues.apache.org/jira/browse/OLINGO-662?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14560608#comment-14560608
 ] 

Prashanth commented on OLINGO-662:
----------------------------------

Hi Christian,

Now i understand the design of olingo for media entities . I would like to make 
2 points :

i) Regarding the validation of request content type : 

As you mentioned, content type of request will not be validated as long as 
entity type is marked with hasStream()==true ( by annotating the property in 
entity pogo with EdmProperty in conjunction with the EdmMediaResourceContent 
annotation ). But here , in our case , we are generating the entity pogo ( ex: 
Issue ) at runtime and this entity doesn't have a property to be marked with 
required annotations (EdmMediaResourceContent ,EdmProperty ). Hence, marking 
entity type with hasStream is not possible in our case and i think the only 
choice we have is to override the method getCustomContentTypes() in processor 
for passing through validation of content type multipart/form-data , 
multipart/mixed etc. Do you have any other suggestion here ? 

PS : Instead of annotating the property of entity with EdmMediaResourceContent 
and EdmProperty , if olingo in future allows to mark the entity pogo ( which 
doesn't have the property to be annotated in our case ) itself with annotations 
, it would be better .

ii) Regarding the readBinary() method of EntityProvider : 

In our case, we want to allow the user to send a request ( either with 
attachment / issue details + attachment ) . So content type would be 
multipart/form-data or multipart/mixed etc. and content(inputstream) of 
createEntity() would be something like following: 

------WebKitFormBoundaryg2ITcoVI9xOjORUq
Content-Disposition: form-data; name="issue_type"

other
------WebKitFormBoundaryg2ITcoVI9xOjORUq
Content-Disposition: form-data; name="issue_priority"

high
------WebKitFormBoundaryg2ITcoVI9xOjORUq
Content-Disposition: form-data; name="testfile.txt"; filename="testfile.txt"
Content-Type: text/plain

file with some content
------WebKitFormBoundaryg2ITcoVI9xOjORUq--


I have gone through the docs and source code of library and understood that 
readBinary() of EntityProvider is simply converting the given inputstream into 
byte[] and returning. But in our case, the InputStream ( content ) of 
createEntity would be having request body ( with some issue details + 
attachments )  and content type would be multipart/form-data or multipart/mixed 
etc. Since, readBinary() of EntityProvider doesn't suite for de-serialization 
of request body ( with some issue details + attachments ) and olingo doesn't 
provide any in-build de-serializer , i am trying to use some other utility ( 
like MultipartStream of Apache commons fileupload ) for parsing and getting the 
issue details and attachments separately. Do you have any better suggestion 
here ? Do you recommend any other de-serializer that we can use for our case ?

PS : If olingo provides an in-built de-serializer in future updates, i think it 
will be useful. Just for example, REST implementations provides some api like 
MultipartBody and Attachment which gives us attachments directly from the 
request body. 

Thanks

> Attachments support in olingo
> -----------------------------
>
>                 Key: OLINGO-662
>                 URL: https://issues.apache.org/jira/browse/OLINGO-662
>             Project: Olingo
>          Issue Type: Bug
>          Components: MISC, odata2-annotation, odata2-core, odata4-server
>    Affects Versions: V2 2.0.3
>            Reporter: Prashanth
>            Assignee: Christian Amend
>            Priority: Blocker
>              Labels: attachments
>
> This question is about the support for attachments uploading and downloading 
> via Olingo Service ( Olingo V2 2.0.3 ). I have gone the olingo docs but 
> didn't find any clue on how to provide support for uploading and downloading 
> of attachments using olingo . 
> Does olingo supports this functionality ? If olingo supports , how to 
> implements this ? 
> Following are some basics which i came to know by debugging the core library :
> -> Media type support : We can provide support for custom content types by 
> overriding the method getCustomContentTypes() in processor class. 
> -> Implementation : we can implement createEntity as following in processor 
> class :
> @Override
>       public ODataResponse createEntity(PostUriInfo uriInfo, InputStream 
> content, 
>       String requestContentType, String contentType) throws ODataException { 
> ... } 
>       
>       But here content is giving the requestBody , not actual file/attachment.
> Note : Here the support for attachments means - ex : in case of Rest , CXF 
> provides some api which can be seen in following snippet :
>       @POST
>       @Consumes( {MediaType.MULTIPART_FORM_DATA })
>       @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
>       public Response create(@Context HttpHeaders httpHeaders, @Context 
> UriInfo uriInfo,
>                       MultipartBody multipartBody)
> Here @Consumes media type provides consumption of multipart formdata and 
> MultipartBody parameter can give us the attachments. 
> Similar to above , Does Olingo V2 2.0.3 provides any API ?How can we 
> implement the support for attachments in Olingo V2 2.0.3 ? Please share us an 
> example !



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to