0

I am try to download a word document which I receive as a base64 string from my web services.

On my html page, I ask the user to enter some data to populate the word and when the user click on a button I would like to download the word document.

Button --> Send to web service --> Create word document --> Send back base64 --> Download this base64 as word document

I am using Downloadify to make this possible in IE9

The probleme is that Downloadify ask for the filename and data on the page load. I get those information only after the user enter the data on the same page.

Downloadify.create('downloadify', {
    filename: filename,
    data: data,
    onComplete: function () {
        alert('Your File Has Been Saved!');
    },
    onCancel: function () {
        alert('You have cancelled the saving of this file.');
    },
    onError: function () {
        alert('You must put something in the File Contents or there will be nothing to save!');
    },
    transparent: false,
    swf: 'js/lib/Downloadify/media/downloadify.swf',
    downloadImage: 'js/lib/Downloadify/images/download.png',
    width: 100,
    height: 30,
    transparent: true,
    append: false
});

Is there a way to bind the filename and data ? Or should I add another page which will already get all the data and will just ask for "Save on disk" ?

Weedoze
  • 13,683
  • 1
  • 33
  • 63

1 Answers1

0

You can probably use an IIFE, e.g.

filename: (function(){return $('#file-name-input').val();}())

I'm assuming that Downloadify will do that lookup only at the time of file save, even though it requires it to be declared in advance.

Otherwise, don't run Downloadify.create(), which generates the download button, until the necessary text boxes have been filled in and confirmed.

btw, in Downloadify docs, they mention that you're allowed to make the data property point to a function. An example for that would be

data: function() { return "data that comprises the file contents"; }

Kyle Baker
  • 3,424
  • 2
  • 23
  • 33