1 package body PER_IMAGE_UPLOAD_PKG as
2 /* $Header: peimgupl.pkb 120.2 2005/08/08 04:51:33 mroberts noship $ */
3
4
5 g_image_is_blob boolean := null;
6
7 function image_is_blob return boolean is
8 l_data_type varchar2(100);
9 l_username varchar2(100);
10 begin
11
12 if g_image_is_blob is null
13 then
14
15
16 -- There may be fnd/ad utility routines for one or
17 -- both of these cursors. To check - and ideally
18 -- replace.
19
20 select u.oracle_username
21 into l_username
22 from fnd_oracle_userid u,
23 fnd_product_installations p
24 where p.application_id = 800
25 and u.oracle_id = p.oracle_id;
26
27 select c.data_type
28 into l_data_type
29 from all_tab_columns c
30 where c.owner = l_username
31 and c.table_name = 'PER_IMAGES'
32 and c.column_name = 'IMAGE' ;
33
34 g_image_is_blob := ( l_data_type = 'BLOB' );
35
36 end if;
37
38 return (g_image_is_blob);
39
40 end image_is_blob;
41
42 -- procedure generic_error - copied from code in:
43 -- $FND_TOP/patch/115/sql/AFCINFOB.pls
44 --
45
46 procedure generic_error(routine in varchar2,
47 errcode in number,
48 errmsg in varchar2) is
49 l_msg varchar2(2000);
50 begin
51 fnd_message.set_name('FND', 'SQL_PLSQL_ERROR');
52 fnd_message.set_token('ROUTINE', routine);
53 fnd_message.set_token('ERRNO', errcode);
54 fnd_message.set_token('REASON', errmsg);
55 fnd_message.raise_error;
56 end;
57
58 --
59 -- Transfer_pvt
60 --
61 -- java wrapper for java upload code
62 --
63
64 function Transfer_pvt (file_id in number,
65 image_id in number,
66 connectString in varchar2,
67 un in varchar2,
68 pw in varchar2,
69 msg in out nocopy varchar2) return number
70 as language java
71 name 'oracle.apps.per.util.ImageUtils.lob_to_img(long,
72 long,
73 java.lang.String,
74 java.lang.String,
75 java.lang.String,
76 java.lang.String[])
77 return int' ;
78
79 --
80 -- Transfer
81 -- Only the file_id,image_id parameters are relevant if the
82 -- PER_IMAGES.IMAGE is a BLOB rather than a LONG RAW
83 function Transfer (file_id in number,
84 image_id in number,
85 connectString in varchar2,
86 un in varchar2,
87 pw in varchar2,
88 msg in out nocopy varchar2) return int is
89
90 l_retval number;
91 --
92 begin
93 --
94
95 if ( image_is_blob )
96 then
97
98 execute immediate
99 'UPDATE PER_IMAGES
100 SET IMAGE = (SELECT FILE_DATA
101 FROM FND_LOBS
102 WHERE FILE_ID = :1)
103 WHERE IMAGE_ID = :2 '
104 using file_id , image_id ;
105
106 if ( sql%rowcount = 1 ) then
107 l_retval := 1 ;
108 else
109 l_retval := 0 ;
110 end if;
111
112 else
113
114 -- call java code
115 l_retval := Transfer_pvt (file_id,
116 image_id,
117 connectString,
118 un,
119 pw,
120 msg);
121 end if;
122
123 return (l_retval);
124
125 exception
126 when others then
127 --
128 -- DK
129 -- The message text for a javavm error contains the main
130 -- details - there is usually a generic error code like
131 -- ORA-29532, ORA-29540. We raise -20001 to ensure that
132 -- the message text is displayed in forms. For some reason
133 -- that message text would not otherwise be displayed.
134 -- This is probably a bug in AOL's message handler
135 --
136 -- sqlcode is not being passed to avoid the error number appearing
137 -- twice
138 --
139 generic_error(routine => 'PER_IMAGE_UPLOAD_PKG',
140 errcode => null,
141 errmsg => sqlerrm);
142
143
144 --
145 end Transfer;
146 --
147
148 --
149 -- LOAD
150 --
151 procedure Load( doc in varchar2,
152 access_id in number ) is
153
154 file_id number ;
155
156 begin
157
158 file_id := fnd_gfm.confirm_upload(
159 access_id => access_id,
160 file_name => doc,
161 program_name => 'PERWSIMG');
162
163 htp.htmlopen;
164 htp.p('Loaded: '||doc||' File ID: '||file_id);
165 htp.htmlclose;
166
167 exception
168 when others then
169 htp.htmlopen;
170 htp.p('error in load');
171 htp.htmlclose;
172 raise;
173 end Load;
174
175 --
176 -- LAUNCH
177 --
178 procedure Launch is
179
180 form_action varchar2(2000);
181 access_id number := fnd_gfm.authorize(NULL);
182 user_id number := fnd_profile.value('USER_ID');
183
184 begin
185
186 form_action := fnd_gfm.construct_upload_url(fnd_web_config.gfm_agent,
187 'per_image_upload_pkg.Load',
188 access_id);
189
190 htp.htmlOpen;
191
192 htp.p('<form action='||form_action||
193 ' method=post enctype="multipart/form-data">');
194
195
196 htp.p('<input type="File" name="doc"></input>');
197
198 htp.p('<input type="Hidden" name="access_id" value='||access_id||'>'||
199 '</input>');
200
201 htp.p('<input type="Hidden" name="user_id" value='||user_id||'>'||
202 '</input>');
203
204 htp.p('<input type="Submit" value="Submit"></input>');
205
206 htp.p('</form>');
207
208 htp.htmlClose;
209
210 end Launch;
211
212 end PER_IMAGE_UPLOAD_PKG;