ofbiz-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Patrick <patrickinminneapo...@gmail.com>
Subject Re: Attaching files to a product
Date Mon, 05 Jul 2010 21:38:36 GMT
First you want to edit the definition of Product in entitymodel.xml to
include string column that points to the path of the uploaded file
and then restart

Then you want to create a service definition in a service.xml file
like the following example

<service name="myServiceName" invoke="myJavaService" engine="java"
location="org.ofbiz.product.feature.ProductFeatureServices">
<attribute name="filedata" type="java.nio.HeapByteBuffer" mode="IN"
optional="false"/>
</service>

Then have a .ftl file with a form like this - notice the encoding.

<form name="serviceName" enctype="multipart/form-data" method="post"
action="<@ofbizUrl>serviceNameControllerRequest</@ofbizUrl>">
  <input type="file" name="filedata" size="50"
onchange="document.getElementById('hidden_filename').value =
this.value;"/>
</form

Now you program myJavaService in java, and you grab filedata from
context, and then you use basic file writing functions to write your
file.
You also need to have a controller.xml file that can handle
serviceNameControllerRequest and invoke myServiceName

public static Map<String, Object> myJavaService(DispatchContext ctx,
Map<String, ? extends Object> context)
{
    java.nio.HeapByteBuffer  buffer = context.get("filedata") ;
   //now write buffer to filesystem
}

there might be other ways to do it.

On Mon, Jul 5, 2010 at 2:43 PM, Olivier Tremblay
<oliviertremblay86@gmail.com> wrote:
> Hi again!
>
> I'm looking for a way to attach pdf files (or any type of files) to a product.
>
> I wish to be able to have our engineers link plans to parts, in such a way that it would
be very simple, viewing any product, to generate a list of all the parts required to build
it, and have access to all the plans for our guys at manufacturing. It would eventually be
useful for a client wanting to change a piece, I think.
>
> Up to now, I have dabbled in the "Content" application, but I don't think I have done
it right. I wanted to create a new content type, called "plans" or something, and be able
to upload that extra piece of information for each product based on the new content type I
created...
>
> The idea is that the engineers could just attach the files themselves with no intervention
on my part whatsoever. Am I on the right track? My googling around and searching on the mailing
list didn't seem to point directly to that, and/or suggested that I couldn't just configure
it on OFBiz out of the box without messing around with the code a little bit.
>
> Thanks again,
>
> Olivier

Mime
View raw message