Sending a cookie value with file download in perl - perl

I've got a submit button on a webpage which performs a file download when clicked.
I'm trying to disable the submit after click (to prevent resubmit while the file is created server-side) then re=enable the submit button when the file is downloaded.
I've almost got it working by following the tutorial below, in short:
When download is clicked get current timestamp and store it in a
hidden field
Send the timestamp with the download request to the server
Server does the file processing
Server creates a cookie with the timestamp value sent from the client
in the original request
Server sends the cookie to the client along with the file to download
On the client if the cookie value matches the hidden field timestamp
the submit is re-enabled
Detecting file download in browser
The problem is that I can't seem to find a way to send the cookie value back to the client with the file download header, if I include set-cookie in the header it breaks the file download process.
Here's my current header, which works:
Content-disposition: attachment; filename=$file; Content-type: $type\n\n$content
If I do this it breaks:
Set-Cookie:$cookie; Content-disposition: attachment; filename=$file; Content-type: $type\n\n$content
I'm creating a cookie on the server with the timestamp value from the client using:
$cookie = CGI::Cookie->new(-name=>'fileDownloadToken',-value=>"$token_value");
Does anyone know how I should go about doing this, coding in Perl?

Ok, I think I've fixed it. Just in case anyone else comes up against this it appeared to be the format of the header, instead of using a single string:
print qq(Content-disposition: attachment; filename=$file; Content-type: $type\n\n$content)
I used this:
print $page->header(
-'cookie' => "$cookie",
-'Content-disposition' => "attachment; filename=\"$file\"",
-'Content-type' => $content
);

Related

How to change data source of report in jasper server using rest service

I am new to Jasper Server. I have successfully created a simple report and pushed it to server and I am able to run it through rest service using postman. Now my next requirement is to change data source of report so that we can have advantage of using same report with different data. I have searched but could not find a working answer. I am using jasper server 8.0.I would appreciate a solution that would work with postman
First we need to get the descriptor of file whose data source we want to change.
Descriptor basically describes our file in server.
Make a “GET” call to the link
http://:/jasperserver/rest_v2/resources/reports/
path/to/report
and set headers to
Content-Type: application/repository.file+json
Accept: application/json
Copy the returned json (descriptor)
Now make a “PUT” call to the link
http://:/jasperserver/rest_v2/resources/reports/
path/to/report
and set headers to (very important)
Content-Type: application/repository.reportUnit+json
Accept: application/json
And inside body paste the descriptor you copied and change the things you want.
and send it.

Image upload with data without multipart/form-data

I need to upload a file (method POST and Content-Type: image/jpeg) with some additionnal information (folderId and userId).
For some reason, on the client side, multipart/form-data is not an option
I thought of passing the folderId and userId in the HTTP headers and the image (jpeg) in the payload.
Does this solution sound OK or is there any other/cleaner way to do ?
Does it look correct and secure in a REST context ?
Note:
Client side would be iOS
No client js in the mean time. If there is a JS client, folderId and userId wont be given by the user through a form.

How to intercept multipart/form data in fiddler and access a binary file which is a part of the request

I am trying to intercept requests send to a server from my mobile device. There is this post request which will upload payload to the server and the request has a file of type .pb, which i cant read in fiddler. Is there a way to get hold of the file ?
It's not clear what "i cant read in fiddler" means.
Use Fiddler's HexView request inspector to inspect the POST body. You can select the bytes of the file upload and choose Save bytes to save the file out to your desktop.

How to show streams inline as HTTP chunked response with play framework

Am following the "Streaming HTTP Response" documentation of Play2! framework which describes how a file or stream could be sent as chunked responses. The http-action code I wrote after reading this is very simple -
Ok.chunked(
Enumerator.fromStream(istream).andThen(Enumerator.eof)
)
With this code everytime I refresh the URL the data in the stream gets downloaded as a file by the browser. Instead of downloading as a file I want the stream content to shown inline in the browser as text. The File example on the documentation page describes how one could do this with files... but looking at the APIs I dont see an inline option with streams. So is it possible to show stream data inline with chunked responses everytime I refresh the browser? If my expectation is invalid then a little explanation of why-so will be very welcome.
From my comment: You should set a content-type supported by your browser (like text/plain or text/xml) when sending the response, otherwise you're just sending bytes and the browser doesn't "know" it can display it.
Update: adding the exact code that solved the issue:
Ok.chunked( Enumerator.fromStream(istream).andThen(Enumerator.eof) ).as("text/html")

Using http request headers with Symfony routing to return different content (html / json)

I'm working on a REST API using the FOSRestBundle and I'd like to be able to use the same URL for returning HTML and JSON depending on the request Accept header; i.e. if you call the URL directly from a browser (Accept : text/html etc) HTML is returned from a twig file, if you are making an AJAX request (Accept : application/JSON etc), JSON is returned using the FOSRestBundle.
Currently I can get this to work by throwing a small if statement at the top of each function to check the request accept header, if it's asking for HTML it returns the twig file, if it's asking for JSON it hits the service.
You should rather send "Accept" header with your requests. Read content negotiation (“Accept” HTTP header) based routing in symfony2.0 and Format listener.
The request scope does not exist when run in command line mode, I had to remove request from each constructor and the problem disappeared.