[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Ftpapi] upload a file (pdf, xml, etc...) from ifs via httpapi...



Gerald,

When a web page creates a form that contains both variables and an "attached" file, it is encoded using a method known as "multipart/form-data".  HTTPAPI has a tool that lets you build a document in multipart/form-data (which I'll refer to as MFD to save typing) by building the MFD file in the IFS.

In your scenario, that would work like this:

1) Create the MFD file on the IFS using HTTPAPI's routines.
2) Add your form fields to it using HTTPAPI's routines.
3) Add the file(s) you wish to attach to it using HTTPAPI's routines.
4) close the MFD File (again with HTTPAPI's routine)
5) Upload the MFD file to the server, just like any other file.
6) Delete the MFD file -- since it was just a temporary object, needed for the file transfer only.

Here's a quick example..  note that this is off the top of my head and untested!  But, it should at least point you in the right direction.  I tried to add a lot of comments to give you the idea...


**free
ctl-opt dftactgrp(*no) bnddir('HTTPAPI');

/copy HTTPAPI_H
/copy IFSIO_H

dcl-s tempFile varchar(40);
dcl-s form pointer;
dcl-s type char(64);
dcl-s rc int(10);

tempFile = http_tempfile();

form = http_mfd_encoder_open(tempFile: type);

// These would be the "regular" form fields:
http_mfd_encoder_addvar_s(form: 'form-variable-1': 'value');
http_mfd_encoder_addvar_s(form: 'form-variable-2': 'value');

// Here's how you attach a file... this would be your
// PDF file...  can be other types, too...  but you'll need to
// use the proper content type (instead of application/pdf)

http_mfd_encoder_addstmf( form
                        : 'form-variable-3'
                        : '/IFS/path/to/yourfile.pdf'
                        : 'application/pdf' );

// if needed, you can call http_mfd_encoder_addstmf multiple
// times if you want to attach multiple files.

http_mfd_encoder_close(form);

// You now have an MFD encoded file in the IFS containing
// the form field(s) and attachment(s) that you added!
// Also the "type" variable has the type of the form that is
// needed by the server.

// Now you can send the file.

rc = http_url_post_stmf( 'http://your-url'
                       : tempFile
                       : '/path/to/response/from/server'
                       : HTTP_TIMEOUT
                       : HTTP_USERAGENT
                       : type );

// this is the IBM-supplied API to delete an IFS file.
// used here to delete our temporary MFD encoded file.

unlink(tempFile);

// handle any errors during post here... etc..

if rc <> 1;
   http_crash();
endif;

*inlr = *on;




On 2/27/17 2:51 PM, Gerald Magnuson wrote:

Thanks Frank…

 

I see that Example7 shows this…

rc = http_url_post_stmf('http://www.scottklement.com/httpapi'    

                          + '/upload.php'                        

                       : tempFile                                

                       : '/tmp/http_result.txt'                  

                       : HTTP_TIMEOUT                             

                       : HTTP_USERAGENT                          

                       : ContentType );                          

 

However, the page I need to hit also has lots of form fields as well….

So, it is like I need to combine   http_url_post_raw with  http_url_post_stmf

 

Somehow?

 

 

 

 

 

Gerald Magnuson | Senior System I Admin



The Knapheide Manufacturing Company
1848 Westphalia Strasse // P.O. Box 7140 // Quincy, IL // 62305-7140
P: 217-592-5291 //   F: 217-592-5046 // www.knapheide.com


    


 

From: ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx [mailto:ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Frank Broome
Sent: Monday, February 27, 2017 12:53 PM
To: FTPAPI/HTTPAPI mailing list <ftpapi@xxxxxxxxxxxxxxxxxxxxxx>
Subject: Re: [Ftpapi] upload a file (pdf, xml, etc...) from ifs via httpapi...

 

Calling this method with the path to the IFS folder as parameter should do it for you: http_url_post_stmf

 

/Frank

 

 

From: ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx [mailto:ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Gerald Magnuson
Sent: Monday, February 27, 2017 10:08 AM
To: FTPAPI/HTTPAPI mailing list
Subject: Re: [Ftpapi] upload a file (pdf, xml, etc...) from ifs via httpapi...

 

Is there a method to “attach” a ifs file using httpapi?

 

 

 

Gerald Magnuson | Senior System I Admin



The Knapheide Manufacturing Company
1848 Westphalia Strasse // P.O. Box 7140 // Quincy, IL // 62305-7140
P: 217-592-5291 //   F: 217-592-5046 // www.knapheide.com


    


 

From: ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx [mailto:ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Frank Broome
Sent: Monday, February 27, 2017 12:03 PM
To: FTPAPI/HTTPAPI mailing list <ftpapi@xxxxxxxxxxxxxxxxxxxxxx>
Subject: Re: [Ftpapi] upload a file (pdf, xml, etc...) from ifs via httpapi...

 

To my knowledge an IFS file is encoded based on the code page of the folder where it is created/stored.

I don’t think the api will be able to change that, as far as I understand.

 

/Frank

 

From: ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx [mailto:ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Gerald Magnuson
Sent: Monday, February 27, 2017 9:47 AM
To: HTTPAPI and FTPAPI Projects (ftpapi@xxxxxxxxxxxxxxxxxxxxxx)
Subject: [Ftpapi] upload a file (pdf, xml, etc...) from ifs via httpapi...

 

We currently have a method to pass “reports” to a web app…

Currently we (from the ibmi) send an email, with the report (be it a pdf, or xml, text, spreadsheet)

The old process would listen for an email, and import the attachment into the report vault.

 

I am now asked to change that process to send a web request, attaching the ifs file…

I am told “you should be able to encode the attachment, like you do on sending a email” to the web call.

 

Does Httpapi have this?

 

 

 

 

Gerald Magnuson | Senior System I Admin



The Knapheide Manufacturing Company
1848 Westphalia Strasse // P.O. Box 7140 // Quincy, IL // 62305-7140
P: 217-592-5291 //   F: 217-592-5046 // www.knapheide.com


    


 

 

Disclaimer

The information contained in this communication from the sender is confidential. It is intended solely for use by the recipient and others authorized to receive it. If you are not the recipient, you are hereby notified that any disclosure, copying, distribution or taking action in relation of the contents of this information is strictly prohibited and may be unlawful.

This email has been scanned for viruses and malware, and may have been automatically archived by Mimecast Ltd, an innovator in Software as a Service (SaaS) for business. Providing a safer and more useful place for your human generated data. Specializing in; Security, archiving and compliance. To find out more Click Here.

 

Disclaimer

The information contained in this communication from the sender is confidential. It is intended solely for use by the recipient and others authorized to receive it. If you are not the recipient, you are hereby notified that any disclosure, copying, distribution or taking action in relation of the contents of this information is strictly prohibited and may be unlawful.

This email has been scanned for viruses and malware, and may have been automatically archived by Mimecast Ltd, an innovator in Software as a Service (SaaS) for business. Providing a safer and more useful place for your human generated data. Specializing in; Security, archiving and compliance. To find out more Click Here.



_______________________________________________
Ftpapi mailing list
Ftpapi@xxxxxxxxxxxxxxxxxxxxxx
http://scottklement.com/mailman/listinfo/ftpapi

_______________________________________________
Ftpapi mailing list
Ftpapi@xxxxxxxxxxxxxxxxxxxxxx
http://scottklement.com/mailman/listinfo/ftpapi