[Building Sakai] Returning binary data (pdf) from Entity Provider?

Steve Swinsburg steve.swinsburg at gmail.com
Thu Nov 8 12:47:51 PST 2012


Hi Curtis,

This is from the ProfileEntityProvider which returns the binary of an image:

final byte[] bytes = image.getBinary();
if(bytes != null && bytes.length > 0) {
	try {
		out.write(bytes);
		ActionReturn actionReturn = new ActionReturn("BASE64", image.getMimeType(), out);
		return actionReturn;
	} catch (IOException e) {
		throw new EntityException("Error retrieving profile image for " + ref.getId() + " : " + e.getMessage(), ref.getReference());
	}
}

ref: https://source.sakaiproject.org/svn/profile2/trunk/tool/src/java/org/sakaiproject/profile2/tool/entityprovider/ProfileEntityProvider.java
Also, in your example, you have the output being sent as text/plain so change that to application/pdf.

cheers,
Steve

On 09/11/2012, at 7:25 AM, Curtis Van-Osch <curtis.van-osch at hec.ca> wrote:

> Hi, 
> I'm trying to have a custom action in my EntityProvider send a PDF back to the browser.  I've figured out how to get the pdf from ContentHostingService, but I can't seem to get any byte data out to the client (even a single character or simple string) through an ActionReturn.
> 
> You can see the test code I've set up in the attached text file.  Whenever I return an ActionReturn with a ByteArrayOuputStream, the client gets a response with 0 Content-Length (as seen in firebug) but a success code (200).
> 
> If I write the data to the OutputStream parameter that is available to the custom action it gets sent to the browser, but in that case I cannot see how to set the content-type to "application/pdf".
> 
> Has anyone tried to do anything similar?  I'd appreciate any input.
> 
> -- 
> Curtis van Osch
> Analyste en informatique
> Service de gestion des technologies de l'information
> HEC Montréal
> 514-340-6000 poste 2029
> curtis.van-osch at hec.ca
> <customActionByte.txt>_______________________________________________
> sakai-dev mailing list
> sakai-dev at collab.sakaiproject.org
> http://collab.sakaiproject.org/mailman/listinfo/sakai-dev
> 
> TO UNSUBSCRIBE: send email to sakai-dev-unsubscribe at collab.sakaiproject.org with a subject of "unsubscribe"

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://collab.sakaiproject.org/pipermail/sakai-dev/attachments/20121109/562860af/attachment.html 


More information about the sakai-dev mailing list