cancel
Showing results for 
Search instead for 
Did you mean: 

Download file in CAP Java using Odata V2 is not working

Abhinandan
Newcomer
0 Kudos
79

Hi Team,

I have been trying to download a image file as an attachment in CAP Java project . I have been able to do so by going through the link https://cap.cloud.sap/docs/guides/providing-services#serving-media-data using Odata V4. But when I try to do the same by using OData V2 (after migrating the same project by going through the link https://cap.cloud.sap/docs/java/migration#v2adapter) , its not downloading as a attachment but its just giving the binary stream as response. Have anybody experienced such issue in CAP Java using Odata V2?

Content In DB CDS
====================
@cds.persistence.skip
entity Books {
  image : LargeBinary @Core.MediaType: 'image/png' @Core.ContentDisposition.Filename:fileName ;
  key fileName : String;
}​
Content in SRV CDS
===================
@readonly entity BookSet as projection on db.Books;

Content in handler
==================
	@On(event = CqnService.EVENT_READ,entity = BookSet_.CDS_NAME)
	public BookSet getBookSet(EventContext context) throws FileNotFoundException,IOException {
		BookSet bookSet = BookSet.create();
		File imageFile = new File("src/main/resources/smile.png");
		bookSet.setImage(new FileInputStream(imageFile));
		bookSet.setFileName("smiley.png");
		return bookSet;
	}

download.jpg

Accepted Solutions (0)

Answers (0)