This is a bit late but since I found this post before I found a solution I thought I would go ahead and share as to possibly help someone else.
There is more information for handling this via JPA and @blob and @lob here:
In my situation I did not want to store the uploaded file in the database but on the file system after some pre-processing. I had a simple JPA Entity called DigitalAudio. It had a number of properties as well as the file system location of the stored file. v2 of OData doesn't have support for Actions and function imports only support GET and POST with parameters only (no request body). The approach I took was to put an additional @Transient property in my entity called AudioFile. I then extended the EDM with a JPAEdmExtension.
******************
@Override
public void extendJPAEdmSchema(JPAEdmSchemaView view) {
Schema schema = view.getEdmSchema();
for (EntityType t : schema.getEntityTypes()) {
if (t.getName().equals("DigitalAudio")) {
t.getProperties().add(getAudioFileProperty());
}
}
}
private Property getAudioFileProperty() {
SimpleProperty property = new SimpleProperty();
JPAEdmMappingImpl mapping = new JPAEdmMappingImpl();
mapping.setJPAType(byte[].class);
property.setName("AudioFile");
property.setType(EdmSimpleTypeKind.Binary);
property.setMapping(mapping);
property.setMimeType("application/octet-stream");
return property;
}
******************
Then I implemented my own ODataJPAProcessor as documented here (note I extended ODataJPAProcessorDefault):
Inside the processor you can override create and update. There you can extract the file as a byte[] and do with it as you please.
Hope this helps someone trying to implement something similar.
Cheers,
Luke