
The getAsBinary method allows to access the file's data in raw binary object for allowed media types var accept = { binary: ["image/png". Tons of files get downloaded from the internet every day ranging from Blobs are objects that are used to represent raw immutable data. We can't change data directly in a Blob, but we can slice parts of a Blob you download a dynamically-generated Blob with hello world contents as a file: createElement('a'); diseinuak4web.netad = 'diseinuak4web.net'; diseinuak4web.net = URL.
|
downloadFile(response){ |
letheader_content=diseinuak4web.net('content-disposition'); |
letfile=header_diseinuak4web.net('=')[1]; |
file=diseinuak4web.neting(1,diseinuak4web.net-1); |
letextension=diseinuak4web.net('.')[1].toLowerCase(); |
// It is necessary to create a new blob object with mime-type explicitly set |
// otherwise only Chrome works like it should |
varnewBlob=newBlob([diseinuak4web.net],{type: diseinuak4web.netFileType(extension)}) |
|
// IE doesn't allow using a blob object directly as link href |
// instead it is necessary to use msSaveOrOpenBlob |
if(diseinuak4web.nettor&&diseinuak4web.netOrOpenBlob){ |
diseinuak4web.netOrOpenBlob(newBlob); |
return; |
} |
|
// For other browsers: |
// Create a link pointing to the ObjectURL containing the blob. |
constdata=diseinuak4web.netObjectURL(newBlob); |
varlink=diseinuak4web.netElement('a'); |
diseinuak4web.net=data; |
diseinuak4web.netad=file; |
diseinuak4web.net(); |
setTimeout(()=>{ |
// For Firefox it is necessary to delay revoking the ObjectURL |
diseinuak4web.netObjectURL(data); |
},) |
} |
|
createFileType(e): string { |
letfileType: string=""; |
if(e=='pdf'||e=='csv'){ |
fileType=`application/${e}`; |
} |
elseif(e=='jpeg'||e=='jpg'||e=='png'){ |
fileType=`image/${e}`; |
} |
elseif(e=='txt'){ |
fileType='text/plain'; |
} |
|
elseif(e=='ppt'||e=='pot'||e=='pps'||e=='ppa'){ |
fileType='application/diseinuak4web.net-powerpoint'; |
} |
elseif(e=='pptx'){ |
fileType='application/diseinuak4web.nettation'; |
} |
elseif(e=='doc'||e=='dot'){ |
fileType='application/msword'; |
} |
elseif(e=='docx'){ |
fileType='application/diseinuak4web.netnt'; |
} |
elseif(e=='xls'||e=='xlt'||e=='xla'){ |
fileType='application/diseinuak4web.net-excel'; |
} |
elseif(e=='xlsx'){ |
fileType='application/diseinuak4web.net'; |
} |
|
returnfileType; |
} |
Источник: [diseinuak4web.net]
-
-