mirror of
https://github.com/PrivateBin/PrivateBin.git
synced 2025-07-30 18:18:37 -04:00
Merge branch 'blob' of https://github.com/otaku/PrivateBin into otaku-blob
This commit is contained in:
commit
de4b96c5ed
3 changed files with 34 additions and 3 deletions
|
@ -1925,7 +1925,37 @@ jQuery.PrivateBin = (function($, sjcl, Base64, RawDeflate) {
|
|||
{
|
||||
var imagePrefix = 'data:image/';
|
||||
|
||||
$attachmentLink.attr('href', attachmentData);
|
||||
// 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>
|
||||
|
||||
// position in data URI string of where data begins
|
||||
var base64Start = attachmentData.indexOf(',') + 1;
|
||||
// position in data URI string of where mediaType ends
|
||||
var mediaTypeEnd = attachmentData.indexOf(';');
|
||||
|
||||
// extract mediaType
|
||||
var mediaType = attachmentData.substring(5, mediaTypeEnd);
|
||||
// extract data and convert to binary
|
||||
var decodedData = Base64.atob(attachmentData.substring(base64Start));
|
||||
|
||||
// Transform into a Blob
|
||||
var decodedDataLength = decodedData.length;
|
||||
var buf = new Uint8Array(decodedDataLength);
|
||||
|
||||
for (var i = 0; i < decodedDataLength; i++) {
|
||||
buf[i] = decodedData.charCodeAt(i);
|
||||
}
|
||||
|
||||
var blob = new window.Blob([ buf ], { type: mediaType });
|
||||
navigator.msSaveBlob(blob, fileName);
|
||||
});
|
||||
} else {
|
||||
$attachmentLink.attr('href', attachmentData);
|
||||
}
|
||||
|
||||
if (typeof fileName !== 'undefined') {
|
||||
$attachmentLink.attr('download', fileName);
|
||||
}
|
||||
|
@ -1971,6 +2001,7 @@ jQuery.PrivateBin = (function($, sjcl, Base64, RawDeflate) {
|
|||
me.hideAttachmentPreview();
|
||||
$attachmentLink.prop('href', '');
|
||||
$attachmentLink.prop('download', '');
|
||||
$attachmentLink.off('click');
|
||||
$attachmentPreview.html('');
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue