[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Save File Stream As .tif Image
Hi Chris
No problem. Attached is my source. It was a proof of concept so there
will be things in there that don't (yet) have any purpose. The code:
* calls web service method 1 for a "job"
* receives one or more file stream ids for that job
* calls web service method 2 for each file stream id
* receives one or more file streams
Thanks to Scott for these service programs!
Paul
On 04/06/2015 15:51, Hayden, Chris wrote:
Paul Park ,
Would you be willing to send your completed program as an attachment ?
[1]www.pilotpen.us
Chris Hayden - Sr. Systems Analyst
Office: (904) 645-9999 ext.1252
Mobile: 904-654-4089
Pilot Corporation of America
3855 Regent Blvd, Jacksonville, Florida 32224 United States
This email and any files transmitted with it are confidential and intended solel
y for the use of the individual or entity to whom they are addressed. If you hav
e received this email in error please notify the system manager. This message co
ntains confidential information and is intended only for the individual named. I
f you are not the named addressee you should not disseminate, distribute or copy
this e-mail. Please notify the sender immediately by e-mail if you have receive
d this e-mail by mistake and delete this e-mail from your system. If you are not
the intended recipient you are notified that disclosing, copying, distributing
or taking any action in reliance on the contents of this information is strictly
prohibited.
-----Original Message-----
From: [2]ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx [[3]mailto:ftpapi-bounces@lists.s
cottklement.com] On Behalf Of Paul Park
Sent: Thursday, June 04, 2015 10:40 AM
To: HTTPAPI and FTPAPI Projects
Subject: Re: Save File Stream As .tif Image
Hi Thomas
I finally got this working by implementing your solution - correctly this time.
I had initially put the http_XmlReturnPtr() directly before my base64_decode, in
stead of prior to the http_url_post_xml() call.The 64k limit finally made sense
to me and the penny dropped.
Thanks very much for all your help, it's much appreciated.
Paul
On 03/06/2015 11:46, Thomas Raddatz wrote:
Paul,
HTTPAPI internally uses a 64k field to pass the element data to your
endOfElement() callback procedure, which most likely is the reason for
the problem.
Maybe you can try to call http_XmlReturnPtr() to let HTTPAPI pass a
pointer to your callback instead of a field. With
http_XmlReturnPtr(*ON) you get a data structure of the following format instead
of a field for 'value':
d value_t ds qualified
d ptr *
d len 10i 0
d EndElement PR
d userdata * value
d depth 10I 0 value
d name 1024A varying const
d path 24576A varying const
d value likeds(value_t) const
d Attrs * dim(32767)
d const options(*varsize)
See also Chris' response to "returning more than 8192 bytes" from 10
th October 2014.
Thomas.
Am 03.06.2015 um 10:26 schrieb Paul Park:
Hi
Thanks very much for the replies!
Thomas: it's base 64 binary data contained within an XML element
called File_Stream. In the procedure that gets called at "end of XML
element", I have this:
P endOfElement b
D endOfElement pi
D userData * value
D depth 10i 0 value
D name 1024a varying const
D path 24576a varying const
D value like(streamBlob) const
D attrs * dim(32767)
D const options(*varsize)
D rc1 S 10I 0
D sb2 s SQLTYPE([4]BLOB:9999999)
D outVar s 32767a varying
/free
select;
// File stream
when name = 'File_Stream';
fd = open(
'/ppk/image.tif':
O_CREAT+O_WRONLY:
S_IWUSR+S_IRUSR+S_IRGRP+S_IROTH);
sb2 = value;
//Convert to base 64
base64_decode( %addr(sb2_data)
: %len(sb2_data)
: %addr(outVar)
: %size(outVar));
rc1 = write(fd: %addr(outVar): %size(outVar));
endsl;
/end-free
P endOfElement e
However, when the base64_decode procedure is called, it fails with
"Unable to decode character at position 65534. (Char=x'40')". When I
debug the program and look at the contents of sb2_data, position
65534 is indeed blank. Positions 1 - 65533 do have data though. How can I fix th
is problem?
Mike: thanks for those code samples. I'll have a go at running them.
I don't think I have a problem viewing tifs (it's hard to know at
this
point!) but those samples are useful for me to get a better idea of
what else I can do with HTTPAPI.
Paul
On 02/06/2015 22:30, Mike Krebs wrote:
How is your ability to download and view any other .tif?
If you want to try, here is a short program to download a .tif to
/tmp/ccitt_1.tif H DFTACTGRP(*NO) BNDDIR('HTTPAPI')
/copy qrpglesrc,httpapi_h
D
rc s 10I 0
D msg s 52A
D URL S 300A varying
D IFS S 256A varying
D errNo S 10i 0
D retries S 10i 0
c callp http_debug(*ON)
c eval URL = '[5]http://www.fileformat.info'
c + '/format/tiff/sample/'
c + '3794038f08df403bb446a97f897c578d/'
c + 'download'
c eval IFS = '/tmp/ccitt_1.tif'
c eval rc = http_url_get(URL: IFS : 5)
if rc = 302;
rc = http_url_get(http_redir_loc: ifs);
/copy qrpglesrc,httpapi_h
D
rc s 10I 0
D msg s 52A
D URL S 300A varying
D IFS S 256A varying
D errNo S 10i 0
D retries S 10i 0
c callp http_debug(*ON)
c eval URL = '[6]http://www.fileformat.info'
c + '/format/tiff/sample/'
c + '3794038f08df403bb446a97f897c578d/'
c + 'download'
c eval IFS = '/tmp/ccitt_1.tif'
c eval rc = http_url_get(URL: IFS : 5)
if rc = 302;
rc = http_url_get(http_redir_loc: ifs);
endif;
c if rc <> 1
c eval retries = 0
c eval msg = http_error(errNo)
c dow errNo = 7 and retries < 5
c callp http_dmsg('rc= ' + %char(rc))
c callp http_dmsg('retries= ' + %char(retries))
c eval rc = http_url_get(URL: IFS : 5)
c if rc = 1
c eval retries = *hival
c else
c eval msg = http_error(errNo)
c eval retries += 1
c endif
c enddo
c endif
c eval *inlr = *on
-----Original Message-----
From: [7]ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx
[[8]mailto:ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Thomas
Raddatz
Sent: Tuesday, June 2, 2015 12:42 PM
To: HTTPAPI and FTPAPI Projects
Subject: Re: Save File Stream As .tif Image
Paul,
What kind of stream do you get back. Is the the binary image stream
or is it an XML message with the image data as part of an xml element?
I assume that you get back an XML message. So how is the binary
image data encoded? Base64? Something else?
Can you provide a sample response message? You may shorten the image
data if it is to big. Just include, let's say, the first 30 and last
30 bytes of the image data.
Thomas.
Am 02.06.2015 um 13:31 schrieb Paul Park:
Hi
The HTTPAPI service programs are working a treat for us, but I have
run into a problem.
I am using http_url_post_xml to post an XML request containing an ID.
The response I get back contains the "file stream" for a .tif
image. I want to save this data in a .tif file, in the IFS, so that
when I open it I can see the image. The image is destined for
display on a web page. So far, I can save the file stream in
example.tif but it doesn't open as an image.
I don't think this is specifically a HTTPAPI problem, but does
anyone know what I need to do to save the file stream properly as a .tif image?
Thanks for any assistance.
Cheers,
Paul
Enterprise Software Systems.
Company No 3374336. Registered in England, Registered Office:
Enterprise House, Pacific Road Altrincham, Cheshire, WA14 5EN
The information in this email is confidential and may be legally
privileged. It is intended solely for the addressee. Access to this
email by anyone else is unauthorized. If you are not the intended
recipient, any disclosure, copying, distribution or any action
taken or omitted to be taken in reliance on it, is prohibited and
may be unlawful. If you are not the intended addressee please
contact the sender and dispose of this e-mail.
-------------------------------------------------------------------
---
- This is the FTPAPI mailing list. To unsubscribe, please go to:
[9]http://www.scottklement.com/mailman/listinfo/ftpapi
-------------------------------------------------------------------
---
-
--------------------------------------------------------------------
--- This is the FTPAPI mailing list. To unsubscribe, please go to:
[10]http://www.scottklement.com/mailman/listinfo/ftpapi
--------------------------------------------------------------------
---
--------------------------------------------------------------------
--- This is the FTPAPI mailing list. To unsubscribe, please go to:
[11]http://www.scottklement.com/mailman/listinfo/ftpapi
--------------------------------------------------------------------
---
Enterprise Software Systems.
Company No 3374336. Registered in England, Registered Office:
Enterprise House, Pacific Road Altrincham, Cheshire, WA14 5EN
The information in this email is confidential and may be legally
privileged. It is intended solely for the addressee. Access to this
email by anyone else is unauthorized. If you are not the intended
recipient, any disclosure, copying, distribution or any action taken
or omitted to be taken in reliance on it, is prohibited and may be
unlawful. If you are not the intended addressee please contact the
sender and dispose of this e-mail.
---------------------------------------------------------------------
-- This is the FTPAPI mailing list. To unsubscribe, please go to:
[12]http://www.scottklement.com/mailman/listinfo/ftpapi
---------------------------------------------------------------------
--
---------------------------------------------------------------------
-- This is the FTPAPI mailing list. To unsubscribe, please go to:
[13]http://www.scottklement.com/mailman/listinfo/ftpapi
---------------------------------------------------------------------
--
Enterprise Software Systems.
Company No 3374336. Registered in England, Registered Office: Enterprise House,
Pacific Road Altrincham, Cheshire, WA14 5EN
The information in this email is confidential and may be legally privileged. It
is intended solely for the addressee. Access to this email by anyone else is una
uthorized. If you are not the intended recipient, any disclosure, copying, distr
ibution or any action taken or omitted to be taken in reliance on it, is prohibi
ted and may be unlawful. If you are not the intended addressee please contact th
e sender and dispose of this e-mail.
-----------------------------------------------------------------------
This is the FTPAPI mailing list. To unsubscribe, please go to:
[14]http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------
__________________________________________________________________
Enterprise Software Systems.
Company No 3374336. Registered in England,
Registered Office: Enterprise House, Pacific Road
Altrincham, Cheshire, WA14 5EN
The information in this email is confidential and may be legally
privileged. It is intended solely for the addressee. Access to this ema
il
by anyone else is unauthorized. If you are not the intended recipient,
any
disclosure, copying, distribution or any action taken or omitted to be
taken in reliance on it, is prohibited and may be unlawful. If you are
not
the intended addressee please contact the sender and dispose of this
e-mail.
References
1. http://www.pilotpen.us/
2. mailto:ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx
3. mailto:ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx
4. BLOB:9999999
5. http://www.fileformat.info/
6. http://www.fileformat.info/
7. mailto:ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx
8. mailto:ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx
9. http://www.scottklement.com/mailman/listinfo/ftpapi
10. http://www.scottklement.com/mailman/listinfo/ftpapi
11. http://www.scottklement.com/mailman/listinfo/ftpapi
12. http://www.scottklement.com/mailman/listinfo/ftpapi
13. http://www.scottklement.com/mailman/listinfo/ftpapi
14. http://www.scottklement.com/mailman/listinfo/ftpapi
H bnddir('LIBHTTP/HTTPAPI') dftactgrp(*no)
H bnddir('BASE64')
/include libhttp/qrpglesrc,httpapi_h
d getdoc pr
d jobDepot 2 const
d jobNumber 7 0 const
d getdoc pi
d jobDepot 2 const
d jobNumber 7 0 const
D startOfElement pr
D userData * value
D depth 10i 0 value
D name 1024a varying const
D path 24576a varying const
D attrs * dim(32767)
D const options(*varsize)
D endOfElement pr
D userData * value
D depth 10i 0 value
D name 1024a varying const
D path 24576a varying const
D value likeds(value_t) const
D attrs * dim(32767)
D const options(*varsize)
D open PR 10I 0 extproc('open')
D path * value options(*string)
D oflag 10I 0 value
D mode 10U 0 value options(*nopass)
D codepage 10U 0 value options(*nopass)
D write PR 10I 0 extproc('write')
D fildes 10I 0 value
D buf * value
D nbyte 10U 0 value
D rename PR 10I 0 ExtProc('Qp0lRenameKeep')
D old * Value options(*string)
D new * Value options(*string)
D close PR 10I 0 extproc('close')
D fildes 10I 0 value
D base64_decode PR 10U 0
D Input * value
D InputLen 10U 0 value
D Output * value
D OutputSize 10U 0 value
D base64_encode pr 10U 0
D Input * value
D InputLen 10U 0 value
D Output * value
D OutputSize 10U 0 value
d value_t ds qualified
d ptr *
d len 10i 0
D soap s 32767a varying
D rc s 10i 0
D error s n
D errorText s 256
D fd s 10u 0
D job s 9
D idx1 s 5i 0
D idx2 s 5i 0
D i s 5i 0
D filePathFrom s 200a
D fileStream ds dim(100) qualified
D id 100 varying
D file 100 dim(100) varying
D O_RDONLY C 1 Reading Only
D O_WRONLY C 2 Writing Only
D O_RDWR C 4 Reading & Writing
D O_CREAT C 8 Create File if not e
D O_EXCL C 16 Exclusively create
D O_TRUNC C 64 Truncate File to 0 b
D O_APPEND C 256 Append to File
D O_CODEPAGE C 8388608 Convert text by code
D O_TEXTDATA C 16777216 Open in text-mode
D S_IRUSR C 256
D S_IWUSR C 128
D S_IXUSR C 64
D S_IRWXU C 448
D S_IRGRP C 32
D S_IWGRP C 16
D S_IXGRP C 8
D S_IRWXG C 56
D S_IROTH C 4
D S_IWOTH C 2
D S_IXOTH C 1
D S_IRWXO C 7
/free
job = jobDepot + %editc(jobNumber:'X');
http_debug(*ON);
// Get all file ids for this job
soap =
'<?xml version="1.0" encoding="utf-8"?>'
+'<soap:Envelope'
+' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'
+' xmlns:xsd="http://www.w3.org/2001/XMLSchema"'
+' xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">'
+'<soap:Header>'
+' <UserCredentials xmlns="xxx">'
+' <userName>stu</userName>'
+' <password>1234</password>'
+' </UserCredentials>'
+'</soap:Header>'
+'<soap:Body>'
+' <GetDocumentByJobNumber xmlns="xxx">'
+' <Job_Number>' + job + '</Job_Number>'
+' <Job_Depot_Code>' + jobDepot + '</Job_Depot_Code>'
+' </GetDocumentByJobNumber>'
+'</soap:Body>'
+'</soap:Envelope>';
// Get pointers to handle the response data
http_XmlReturnPtr(*ON);
rc = http_url_post_xml(
'https://xxx.asmx' +
'?op=GetDocumentByJobNumber'
: %addr(soap) + 2
: %len(soap)
: %paddr(startOfElement)
: %paddr(endOfElement)
: *null);
select;
when rc <> 1; //?B
error = *on;
errorText = http_error();
endsl;
// For each file stream id, get the scanned documents
for i = 1 to idx1;
soap =
'<?xml version="1.0" encoding="utf-8"?>'
+'<soap:Envelope'
+' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'
+' xmlns:xsd="http://www.w3.org/2001/XMLSchema"'
+' xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">'
+'<soap:Header>'
+' <UserCredentials xmlns="xxx">'
+' <userName>stu</userName>'
+' <password>1234</password>'
+' </UserCredentials>'
+'</soap:Header>'
+'<soap:Body>'
+' <GetScanDocument xmlns="xxx">'
+' <Document_ID>' + fileStream(i).id + '</Document_ID>'
+' </GetScanDocument>'
+'</soap:Body>'
+'</soap:Envelope>';
rc = http_url_post_xml(
'https://xxx.asmx' +
'?op=GetScanDocument'
: %addr(soap) + 2
: %len(soap)
: %paddr(startOfElement)
: %paddr(endOfElement)
: *null);
select;
when rc <> 1; //
error = *on;
errorText = http_error();
endsl;
endfor;
*inlr = *on;
return;
/end-free
//============================================================================
// startOfElement: process the start of element
//============================================================================
p startOfElement b
D startOfElement pi
D userData * value
D depth 10i 0 value
D name 1024a varying const
D path 24576a varying const
D attrs * dim(32767)
D const options(*varsize)
/free
select;
// Increment the count of file stream ids
when name = 'ScanDetails';
idx1 += 1;
idx2 = 0;
// Increment the count of files within file stream ids
when name = 'ScanFileDetails';
idx2 += 1;
endsl;
/end-free
p startOfElement e
//============================================================================
// endOfElement: process the end of an element
//============================================================================
P endOfElement b
D endOfElement pi
D userData * value
D depth 10i 0 value
D name 1024a varying const
D path 24576a varying const
D value likeds(value_t) const
D attrs * dim(32767)
D const options(*varsize)
D rc1 S 10I 0
D outVar s SQLTYPE(BLOB:9999999) inz
D inLen s 20i 0
D outLen s 20i 0
D valueData s 100a based(value.ptr)
D timestamp s 26a
D filePathTo s 200a
D fileName s 100a
/free
select;
// Write a dummy file with timestamp as its name. filePathFrom is global!
when name = 'File_Stream';
timestamp = %char(%timestamp());
filePathFrom = '/xxx/' + timestamp;
fd = open(
filePathFrom:
O_CREAT+O_WRONLY:
S_IWUSR+S_IRUSR+S_IRGRP+S_IROTH);
inLen = %len(value);
//?Convert to base 64
outLen = base64_decode( value.ptr
: value.len
: %addr(outVar_data)
: %len(outVar));
rc1 = write(fd: %addr(outVar_data): %len(outVar));
callp close(fd);
when name = 'File_Stream_ID';
fileStream(idx1).id = %subst(valueData:1:value.len);
// Now that we have the file name, rename the dummy file to it
when name = 'Filename';
fileName = %subst(valueData:1:value.len);
fileStream(idx1).file(idx2) = fileName;
filePathTo = '/xxx/' + fileName;
rc1 = rename(filePathFrom:
%trim(filePathTo));
endsl;
/end-free
P endOfElement e
-----------------------------------------------------------------------
This is the FTPAPI mailing list. To unsubscribe, please go to:
http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------