Hello,
we want to implement a REST-API in our application.
One of the function must be the mutipart/form-data save of files.
We done some tests with the DUMP_FILE_CONTENTS, but we dont realy understand the function.
Is there enyone who use this and can give us an example how to use it?
THX a lot.
Hi
DUMP_FILE_CONTENTS is for downloading a file FROM an external API.
If you want to implement a REST-API you should build an USP that "gives" the file and ends with something like this
putitem/id $webinfo("HTTPRESPONSEHEADERS"), "cache-control", "no-cache"
putitem/id $webinfo("HTTPRESPONSEHEADERS"), "Content-Type", your_media_type
putitem/id $webinfo("HTTPRESPONSEHEADERS"), "Expires", "0"
putitem/id $webinfo("HTTPRESPONSEHEADERS"), "Pragma", "no-cache"
putitem/id $webinfo("HTTPRESPONSEHEADERS"), "Access-Control-Allow-Origin", "*"
$webinfo("output") = the contents of the file you want to giveAnd, maybe, adding this to set the file name.
putitem/id $webinfo("HTTPRESPONSEHEADERS"), "Content-disposition", "inline; filename=a_file_name"Hope this helps
---
Luis Vila
Hi
DUMP_FILE_CONTENTS is for downloading a file FROM an external API.
If you want to implement a REST-API you should build an USP that "gives" the file and ends with something like this
putitem/id $webinfo("HTTPRESPONSEHEADERS"), "cache-control", "no-cache"
putitem/id $webinfo("HTTPRESPONSEHEADERS"), "Content-Type", your_media_type
putitem/id $webinfo("HTTPRESPONSEHEADERS"), "Expires", "0"
putitem/id $webinfo("HTTPRESPONSEHEADERS"), "Pragma", "no-cache"
putitem/id $webinfo("HTTPRESPONSEHEADERS"), "Access-Control-Allow-Origin", "*"
$webinfo("output") = the contents of the file you want to giveAnd, maybe, adding this to set the file name.
putitem/id $webinfo("HTTPRESPONSEHEADERS"), "Content-disposition", "inline; filename=a_file_name"Hope this helps
---
Luis Vila
Hello Luis, tanks a lot, but i we want to receive Files from a nother Rest-api. 😉
Hello,
we want to implement a REST-API in our application.
One of the function must be the mutipart/form-data save of files.
We done some tests with the DUMP_FILE_CONTENTS, but we dont realy understand the function.
Is there enyone who use this and can give us an example how to use it?
THX a lot.
Hi
I have no sample with multipart/form-data. I think DUMP_FILE_CONTENTS is oriented to binary files (because Content parameter of SEND operation is a string).
vc_URL = "https://community.uniface.com/plugins/servlet/themepress/brikitservlet/designs/themes/Uniface/images/Uniface_Colored-Logo_RGB.png"
newinstance "UHTTP", vhHTTP
vhHTTP->set_flags(3)
vhHTTP->dump_file_contents("uniface.png", "")
vhHTTP->send(vc_URL, "GET", "", "", vaHEAD, vcBODY, vcRESP)
vhHTTP->dump_file_contents("", "")I understand dump_file_contents as: Look, I am going to ask for something but just dump the contents into this file. And I guess its a way to skip vcBODY string-limitation (vcBODY will be empty when used with dump_file_contents). If you comment both dump_file_contents lines, vcBODY will get a raw representation... till the first \\0 char.
Hi
I have no sample with multipart/form-data. I think DUMP_FILE_CONTENTS is oriented to binary files (because Content parameter of SEND operation is a string).
vc_URL = "https://community.uniface.com/plugins/servlet/themepress/brikitservlet/designs/themes/Uniface/images/Uniface_Colored-Logo_RGB.png"
newinstance "UHTTP", vhHTTP
vhHTTP->set_flags(3)
vhHTTP->dump_file_contents("uniface.png", "")
vhHTTP->send(vc_URL, "GET", "", "", vaHEAD, vcBODY, vcRESP)
vhHTTP->dump_file_contents("", "")I understand dump_file_contents as: Look, I am going to ask for something but just dump the contents into this file. And I guess its a way to skip vcBODY string-limitation (vcBODY will be empty when used with dump_file_contents). If you comment both dump_file_contents lines, vcBODY will get a raw representation... till the first \\0 char.
Hi Luis, thank this is the right way for me. We test it, and it works how we want.
The File will be downloadet into the directory we configure in the urouter asn for dir-param.
But in vcBODY there is nothing!?
But it will be interesting how it works with a raw content-body
THX a lot Dirk
Hi
I have no sample with multipart/form-data. I think DUMP_FILE_CONTENTS is oriented to binary files (because Content parameter of SEND operation is a string).
vc_URL = "https://community.uniface.com/plugins/servlet/themepress/brikitservlet/designs/themes/Uniface/images/Uniface_Colored-Logo_RGB.png"
newinstance "UHTTP", vhHTTP
vhHTTP->set_flags(3)
vhHTTP->dump_file_contents("uniface.png", "")
vhHTTP->send(vc_URL, "GET", "", "", vaHEAD, vcBODY, vcRESP)
vhHTTP->dump_file_contents("", "")I understand dump_file_contents as: Look, I am going to ask for something but just dump the contents into this file. And I guess its a way to skip vcBODY string-limitation (vcBODY will be empty when used with dump_file_contents). If you comment both dump_file_contents lines, vcBODY will get a raw representation... till the first \\0 char.
As far as I know, Uniface comes with curl libraries which, of course, is able to handle binaries. The problem with UHTTP is this vcBODY parameter because it is string.
It works fine when the response is a string. It also works with chunks if response is too big (see read_content operation).
But when a binary is received, send operation is not able to handle because of this string parameter.
It seems dump_file_contents appear to solve this problem.
- First, to set-up send operation to inform it that it should not work as usual.
- Second, to act as read_content operation (after operation send), to be able to work with chunks if response is too big.
So, as dump_file_contents is replacing this string parameter... Help mentions that vcBODY will be empty when used in combination with dump_file_contents. The examples use just a "" in this parameter but I included vcBODY for better understanding.
If your downloaded data is a string... you don't need to use dump_file_contents. The normal use of vhHTTP→send(..., vcBODY, vcRESP) is enough.
Regards