Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blob is not defined #1378

Closed
blakeembrey opened this issue Jul 14, 2020 · 7 comments · Fixed by #1384
Closed

Blob is not defined #1378

blakeembrey opened this issue Jul 14, 2020 · 7 comments · Fixed by #1384

Comments

@blakeembrey
Copy link
Contributor

Describe the bug

When using the AWS SDK with Cloudflare Workers I get a Blob is not defined error.

SDK version number 1.0.0-gamma.4

Is the issue in the browser/Node.js/ReactNative? Web worker pseudo environment

Details of the browser/Node.js/ReactNative version N/A

To Reproduce (observed behavior) Same as #1165 (comment).

Expected behavior It should not fail.

Additional context

It should be possible to remove Blob usage from the main path since it appears to be there primarily for older browser support? #1165 (comment).

@AllanZhengYP
Copy link
Contributor

Hi @blakeembrey

Have you tried polyfilling Blob for your runtime? Blob constructor is very wildly supported in browsers, and it's hard to avoid them in the browser code path. Given we don't officially support CloudFlare workers and it's hard to test whether we can do it right, polyfilling the Blob is more viable solution.

@blakeembrey
Copy link
Contributor Author

blakeembrey commented Jul 15, 2020

What about in web workers (I actually have no idea if Blob exists in web workers)? Also, as far as I can tell, there's only two code paths relying on it and they're both easy to change code paths. One seems to be a handler for older browsers without readable streams, the other was just to count the number of bytes in a string.

@blakeembrey
Copy link
Contributor Author

Also happy to submit a PR with the appropriate changes needed. Polyfilling Blob seems like more work than it's worth since I'm not aware of any existing polyfills. Currently I'm just using aws4fetch instead, but it's getting tedious having to reimplement each interface (SES, DynamoDB and KMS so far).

@AllanZhengYP
Copy link
Contributor

AllanZhengYP commented Jul 15, 2020

@blakeembrey

Sure I'm happy to review the PR. To your question:

What about in web workers (I actually have no idea if Blob exists in web workers)?

I did a little experiment from my console, and I think they are available. Here's what I did:

const response = "self.onmessage=function(e){postMessage('Worker: '+new Blob(['hello world']));}";
let blob;
try {
    blob = new Blob([response], {type: 'application/javascript'});
} catch (e) { // Backwards-compatibility
    window.BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder;
    blob = new BlobBuilder();
    blob.append(response);
    blob = blob.getBlob();
}
var worker = new Worker(URL.createObjectURL(blob));
worker.onmessage = function(e) {
    alert('Response: ' + e.data);
};
worker.postMessage('Test');

@trivikr
Copy link
Member

trivikr commented Jul 21, 2020

@blakeembrey Can you verify if this is fixed in release v1.0.0-gamma.5 (i.e. in @aws-sdk/client-dynamodb@1.0.0-gamma.5)?

@blakeembrey
Copy link
Contributor Author

I'm not currently using the DynamoDB client, but confirmed it works with KMS and SES now so I bet DynamoDB also works now. Thanks!

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants