Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function getBlobUrl(file) {
if (file.blobUrl) {
blobUtil.revokeObjectURL(file.blobUrl);
}
const fileBlob = blobUtil.createBlob([file.content], { type: 'text/plain' });
const blobURL = blobUtil.createObjectURL(fileBlob);
return blobURL;
}
return new Promise((resolve, reject) => {
if (!isBlobbable(file) && !hasReaderSupport) {
reject(new Error('File is not a blob'))
}
const canvas = document.createElement('canvas')
const ctx = canvas.getContext('2d')
const img = new Image()
img.src = blobUtil.createObjectURL(file)
img.onload = () => {
const width = img.width
const height = img.height
const resizedWidth = options.width ? Math.ceil(options.width) : width / 2
const resizedHeight = Math.ceil(height * resizedWidth / width)
canvas.width = width
canvas.height = height
ctx.drawImage(img, 0, 0)
blobUtil.canvasToBlob(hermiteResize(canvas, width, height, resizedWidth, resizedHeight))
.then(blob => {
blobUtil.revokeObjectURL(img.src)
resolve(blob)
})
export function getUrlFromBlob (blob) {
return isBlobbable(blob)
? blobUtil.createObjectURL(blob)
: ''
}