How to change the filename in http_mfd_encoder_addstmf

Discussions related to HTTPAPI (An HTTP Client Package for RPG programming.) http://www.scottklement.com/httpapi/
Post Reply
sgonchigar
Posts: 5
Joined: Tue May 10, 2022 4:46 pm

How to change the filename in http_mfd_encoder_addstmf

Post by sgonchigar »

Hello,

I am using http_mfd_encoder_addstmf to upload files, the content disposition filename shows the full IFS path. Wondering if there is a way to override that.

Example: Request header
Content-Disposition: form-data; name="file"; filename="/home/user/pdf/<pdf_filename>"
Content-Type: application/octet-stream

Thank you,
Sunil
Scott Klement
Site Admin
Posts: 305
Joined: Sun Jul 04, 2021 5:12 am

Re: How to change the filename in http_mfd_encoder_addstmf

Post by Scott Klement »

Currently there isn't an option in HTTPAPI to remove the path, but you could do it with:
  1. Use the IFS chdir() procedure to switch to the directory containing the attachment.
  2. only use the filename (not the entire pathname) when calling http_mfd_encoder_addstmf
For example:

Code: Select all

/copy IFSIO_H
.
.
chdir('/home/usr/pdf');
http_mfd_encoder_addstmf(enc: 'file': 'pdf_filename.pdf': 'application/pdf');
Or, if you prefer an option could be added to HTTPAPI to strip off the path. Nobody has needed this yet (since the server typically ignores the path, anyway) but it could be added as an option if the above doesn't work well enough for you.
sgonchigar
Posts: 5
Joined: Tue May 10, 2022 4:46 pm

Re: How to change the filename in http_mfd_encoder_addstmf

Post by sgonchigar »

Thank you Scott for the response. I tried the IFS chgdir(). It did not attach the file.
The REST service had a limitation on the file name length of 64 char and 10 char for the extension. I realized what my issue was after you mentioned that the path is ignored by the host system. I was appending 26 char timestamp to the file that I was working with to keep it unique for troubleshooting purpose. I removed the logic to append timestamp and now the length is less than 64 char and getting successful response. I am good with leaving http_mfd_encoder_addstmf as is.

Thank you again for the quick response.
Post Reply