Storing custom field file to local file system

I am writing a custom dhandler for a CMMS/Work Order system based on
RT/AT.

Essentially I have a Work Order Template (an OpenOffice ODT file with
user-defined fields) that I populate with custom fields from an RT
Ticket using command-line XMLstarlet tool.

Everything is working when I store my template document on the file
system… ie. my $file = dirname($m->current_comp->source_file) .
‘/MaintenanceWO.odt’;

But I want to get the template document from an Asset Custom Field.

From outside of RT, and using LWP::Simple - I can do this - which works:

my $asset = RTx::AssetTracker::Asset->new($RT::SystemUser);
my $cf = RT::CustomFieldValue->new($RT::SystemUser);

$asset->Load(“WO Template”);
$cf = $asset->CustomFieldValues(“File”)->First;

my $id = $cf->Id;

my $url = RT->Config->Get(‘WebPath’) .
“/Download/CustomFieldValue/”.$cf->Id.‘/’.$cf->Content;
getstore($url,“/tmp/temp.odt”);

Unfortunately from within the dhandler it does not work. There are
authentication issues… ie. it returns the RT login html instead of the
template document.

I tried appending “?user=rtuser&pass=rtpassword” to the url, but no
luck.

Within RT itself, is there a “LWP::Simple::getstore” equivalent??

Or perhaps more easily put: How do you extract a file from a custom
field and store it on the local file system?

Thanks,

-Bob

my $url = RT->Config->Get(‘WebPath’) .
“/Download/CustomFieldValue/”.$cf->Id.‘/’.$cf->Content;
getstore($url,“/tmp/temp.odt”);

Or perhaps more easily put: How do you extract a file from a custom
field and store it on the local file system?

Since the custom field just names the file, set up a separate name space in
your web server (Apache?) that doesn’t go through RT to fetch the document
through with getstore().

my $url = “http://not-rt.server.com/some/dir/” . $cf->Content;
getstore($url…);

If you need to secure it better make sure not-rt.server.com isn’t publicly
available, or use “localhost” and clamp that down in Apache config, or whatever.

If you need RT to authenticate document access, then you’re better off
storing the document as an attachment.

– ============================
Tom Lahti
BIT Statement LLC

(425)251-0833 x 117
http://www.bitstatement.net/
– ============================

Thanks Tom - but actually my custom field IS defined as “Upload one
file” (or an attachment).

My problem is saving that attachment from RT to /tmp (for manipulation
from command-line script).

There must be some non-http method of extracting the attachment to a
file?-----Original Message-----
From: Tom Lahti toml@bitstatement.net
To: BJ Blanchard blabj@dainty.ca
Cc: RT-Users@lists.bestpractical.com
Subject: Re: [rt-users] Storing custom field file to local file system
Date: Tue, 02 Jun 2009 13:42:07 -0700

my $url = RT->Config->Get(‘WebPath’) .
“/Download/CustomFieldValue/”.$cf->Id.‘/’.$cf->Content;
getstore($url,“/tmp/temp.odt”);

Or perhaps more easily put: How do you extract a file from a custom
field and store it on the local file system?

Since the custom field just names the file, set up a separate name space in
your web server (Apache?) that doesn’t go through RT to fetch the document
through with getstore().

my $url = “http://not-rt.server.com/some/dir/” . $cf->Content;
getstore($url…);

If you need to secure it better make sure not-rt.server.com isn’t publicly
available, or use “localhost” and clamp that down in Apache config, or whatever.

If you need RT to authenticate document access, then you’re better off
storing the document as an attachment.

Thanks Tom - but actually my custom field IS defined as “Upload one
file” (or an attachment).
My problem is saving that attachment from RT to /tmp (for
manipulation from command-line script).
There must be some non-http method of extracting the attachment to
a file?

Look at Download/CustomFieldValue/dhandler

You need to get an ObjectCustomFieldValue object and then fetch the
LargeContent

-kevin

Kevin Falcone wrote:> On Jun 3, 2009, at 7:23 AM, BJ Blanchard wrote:

Thanks Tom - but actually my custom field IS defined as “Upload one
file” (or an attachment).
My problem is saving that attachment from RT to /tmp (for
manipulation from command-line script).
There must be some non-http method of extracting the attachment to
a file?

Look at Download/CustomFieldValue/dhandler

You need to get an ObjectCustomFieldValue object and then fetch the
LargeContent

Also, if its an attachment you can get it through the REST interface.

http://wiki.bestpractical.com/view/REST

– ============================
Tom Lahti
BIT Statement LLC

(425)251-0833 x 117
http://www.bitstatement.net/
– ============================