Home » Community » Newbie corner » Skylark app - create pdf and donwload it
Skylark app - create pdf and donwload it [message #55986] |
Sat, 09 January 2021 13:47  |
BetoValle
Messages: 204 Registered: September 2020 Location: Brasil Valinhos SP
|
Experienced Member |
|
|
Hi,
I haven't found an example of how to create a pdf and download it using a skylark application.
could someone suggest an example to me?
Thanks!
|
|
|
|
|
Re: Skylark app - create pdf and donwload it [message #55991 is a reply to message #55990] |
Sat, 09 January 2021 20:28  |
 |
Xemuth
Messages: 387 Registered: August 2018 Location: France
|
Senior Member |
|
|
Well, to generate a PDF I can't realy help you. But to download a file via skylark I did this :
SKYLARK(DownloadURL,"/url/**"){
if( http.GetParamCount() > 0){
bool find = false;
for(FileURL& fu : GetApp().AllURL){
if(fu.URL.IsEqual((String)http[0])){
find = true;
if(fu.file){
if(FileExists(fu.file->FilePath)){
if(fu.TotalDownloadNumber == -2 || (fu.TotalDownloadNumber > fu.DownloadNumber)){
fu.DownloadNumber++;
http.SetHeader("content-disposition", "attachment; filename=\"" + fu.file->FileName +"\"").ContentType("application/octet-stream") << LoadFile(fu.file->FilePath);
}else{
http.SetHeader("content-disposition", "attachment; filename=\"" + fu.file->FileName +"\"").ContentType("application/octet-stream") << LoadFile(fu.file->FilePath);
GetApp().RemoveURL(fu.Id);
}
}else{
http("FILEREQUIRED","url/")("ERROR_CODE",204)("ERROR_STRING", "File no longer exist on server.").RenderResult("views/notFound").Response(204,"File no longer exist");
}
}else{
http("FILEREQUIRED","url/")("ERROR_CODE",204)("ERROR_STRING", "File no longer exist on server.").RenderResult("views/notFound").Response(204,"File no longer exist");
}
break;
}
}
if(!find){
http("FILEREQUIRED","url/")("ERROR_CODE",404)("ERROR_STRING", "Bad URL requested.").RenderResult("views/notFound").Response(404,"Bad URL requested");
}else{
http("FILEREQUIRED","url/")("ERROR_CODE",400)("ERROR_STRING", "Something went wrong.").RenderResult("views/notFound").Response(400,"Something went wrong");
}
}else{
http("FILEREQUIRED","url" )("ERROR_CODE",400)("ERROR_STRING", "Bad request, no argument passed.").RenderResult("views/notFound").Response(400,"Bad request, no argument passed");
}
}
The importante line is :
http.SetHeader("content-disposition", "attachment; filename=\"" + fu.file->FileName +"\"").ContentType("application/octet-stream") << LoadFile(fu.file->FilePath);
[Updated on: Sat, 09 January 2021 20:30] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Sun May 11 07:01:35 CEST 2025
Total time taken to generate the page: 0.00392 seconds
|