Use blob URI for saving attachments (#432)
This commit is contained in:
parent
a459c4692c
commit
ff6b9bd8f9
|
@ -2514,10 +2514,6 @@ jQuery.PrivateBin = (function($, RawDeflate) {
|
||||||
*/
|
*/
|
||||||
me.setAttachment = function(attachmentData, fileName)
|
me.setAttachment = function(attachmentData, fileName)
|
||||||
{
|
{
|
||||||
// IE does not support setting a data URI on an a element
|
|
||||||
// Convert dataURI to a Blob and use msSaveBlob to download
|
|
||||||
if (window.Blob && navigator.msSaveBlob) {
|
|
||||||
$attachmentLink.off('click').on('click', function () {
|
|
||||||
// data URI format: data:[<mediaType>][;base64],<data>
|
// data URI format: data:[<mediaType>][;base64],<data>
|
||||||
|
|
||||||
// position in data URI string of where data begins
|
// position in data URI string of where data begins
|
||||||
|
@ -2536,10 +2532,15 @@ jQuery.PrivateBin = (function($, RawDeflate) {
|
||||||
buf[i] = decodedData.charCodeAt(i);
|
buf[i] = decodedData.charCodeAt(i);
|
||||||
}
|
}
|
||||||
const blob = new window.Blob([ buf ], { type: mediaType });
|
const blob = new window.Blob([ buf ], { type: mediaType });
|
||||||
|
|
||||||
|
// IE does not support setting a data URI on an a element
|
||||||
|
// Using msSaveBlob to download
|
||||||
|
if (window.Blob && navigator.msSaveBlob) {
|
||||||
|
$attachmentLink.off('click').on('click', function () {
|
||||||
navigator.msSaveBlob(blob, fileName);
|
navigator.msSaveBlob(blob, fileName);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
$attachmentLink.attr('href', attachmentData);
|
$attachmentLink.attr('href', window.URL.createObjectURL(blob));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof fileName !== 'undefined') {
|
if (typeof fileName !== 'undefined') {
|
||||||
|
|
Loading…
Reference in New Issue