Skip to content

Commit

Permalink
Fix slice on payloadFromBlob throwing exception
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmoreira committed Apr 27, 2020
1 parent 34eab5a commit 3b2f4ea
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
7 changes: 2 additions & 5 deletions codemod/output/Evaporate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
removeAtIndex,
readableFileSize,
s3EncodedObjectName,
getBlobSlice
getSupportedBlobSlice
} from './Utils'

class Evaporate {
Expand Down Expand Up @@ -478,10 +478,7 @@ class Evaporate {
return 'Option readableStreamPartMethod is required when readableStreams is set.'
}
} else {
if (
typeof Blob === 'undefined' ||
typeof getBlobSlice() === 'undefined'
) {
if (!getSupportedBlobSlice()) {
return 'Evaporate requires support for Blob [webkitSlice || mozSlice || slice]'
}
}
Expand Down
8 changes: 4 additions & 4 deletions codemod/output/PutPart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
ERROR,
PAUSING
} from './Constants'
import { getBlobSlice } from './Utils'
import { getSupportedBlobSlice } from './Utils'

//http://docs.aws.amazon.com/AmazonS3/latest/API/mpUploadUploadPart.html
class PutPart extends SignedS3AWSRequest {
Expand Down Expand Up @@ -299,10 +299,10 @@ class PutPart extends SignedS3AWSRequest {
// 2nd parameter changed. For example Gecko went from slice(start,length) -> mozSlice(start, end) -> slice(start, end).
// As of 12/12/12, it seems that the unified 'slice' is the best bet, hence it being first in the list. See
// https://developer.mozilla.org/en-US/docs/DOM/Blob for more info.
const file = this.fileUpload.file
const { file } = this.fileUpload

const slicerFn = getBlobSlice()
const blob = slicerFn(this.start, this.end)
const slicerKey = getSupportedBlobSlice()
const blob = file[slicerKey](this.start, this.end)

if (this.con.computeContentMd5) {
return new Promise(resolve => {
Expand Down
15 changes: 8 additions & 7 deletions codemod/output/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,13 @@ function noOpLogger() {
}
}

function getBlobSlice() {
return (
Blob.prototype.slice ||
(Blob as any).prototype.webkitSlice ||
(Blob as any).prototype.mozSlice
)
function getSupportedBlobSlice() {
if (typeof Blob === 'undefined') {
return null
}

const blobProperties = Object.keys(Blob.prototype)
return blobProperties.find(key => key.toLowerCase().includes('slice'))
}

export {
Expand All @@ -260,5 +261,5 @@ export {
removeAtIndex,
readableFileSize,
noOpLogger,
getBlobSlice
getSupportedBlobSlice
}

0 comments on commit 3b2f4ea

Please sign in to comment.