0

I'm creating an object tag with jQuery to visualise a dynamic generated PDF file. In order to create it, I'm using the "data" attribute to include GET parameters in the url, so the server can identify what kind of file is needed.

$("#div").html("<object data='url?parameterX=1&parameterY=0' type='application/pdf'></object>");

in the same project, I now need to generate a pdf file with a dynamic generated picture. I'm able to do that with the html2canvas library and sending via POST the base64 value of the image, but since I need to show the file in the object tag, I'm unable to send the the base64 data as GET, and thus the browser shows the message "URL too long".

Is it possible create the Object tag with a complex parameter? I don't know if is possible send the information via POST.

Update

For now, the only way to solve this was the James Thorpe recommendation. with jquery ajax, i'm sending the base64 to the server and storing the value in a session variable. Something like this:

$.ajax({
  url: "url",
  dataType: "text",
  type: "POST",
  data: { image: canvas.toDataURL("image/png").replace("data:image/png;base64,", "") }
}).done(function (data) {
  $("#div").html("<object data='url?parameterX=1' type='application/pdf'></object>");
}

however, i don't know if this is the best solution. i'm gonna leave the question open and i will try to provide any update if i found something useful.

ViROscar
  • 148
  • 1
  • 11
  • You're doing something wrong if you're getting a message saying the URL is too long, since the limit is roughly 2,000 characters. What do you mean by complex parameters? And anything can be sent via POST. – Waxi Jan 12 '15 at 15:46
  • The complex parameter is the base64 value of a image. about 182845 characters. i know, i can send the base64 value using POST. but i need to create a object tag to display a PDF with the image. – ViROscar Jan 12 '15 at 16:04
  • Try looking into base64 url encode? http://stackoverflow.com/questions/1374753/passing-base64-encoded-strings-in-url – Waxi Jan 12 '15 at 16:09
  • @slime — Did you read the question? That results in URLs that are too long. – Quentin Jan 12 '15 at 16:10
  • Can you avoid roundtripping the data to the client entirely, instead keep the data on the server and point the `object` at a different URL which uses an ID to look up the data and invoke the html2canvas functionality – James Thorpe Jan 12 '15 at 16:10
  • 1
    I'd experiment with dynamically generating a `
    ` and POSTing it (with `target`) to an `
    – Quentin Jan 12 '15 at 16:11
  • @Quentin Apparently not well enough, but how about urlencode()? – Waxi Jan 12 '15 at 16:12
  • 1
    Or if the data is only on the client, ajax post it to a page that stores it and returns an ID. Then use that ID in the URL with the redirect page as above. – James Thorpe Jan 12 '15 at 16:18
  • @slime — Wouldn't be able to deal with binary input. Wouldn't make base64 data any shorter. – Quentin Jan 12 '15 at 16:21
  • @Quentin unfortunate for me, the iframe acts different depending of the browser. thats why im using an Object tag. – ViROscar Jan 12 '15 at 17:29
  • @JamesThorpe is a good approach and i can use as an alternative but my main goal is trying to do with few request to the server, or trying avoid the use of session variables for storing a temporal value. – ViROscar Jan 12 '15 at 17:33

0 Answers0