S3 putObject promise works in Google Chrome, but does not return in time in Edge

0

Creating a simple app to upload files to S3 bucket from browser. The code works just fine in Google Chrome. It does not work in Edge, however, if I run debug mode and step through the code, then it works in Edge. It appears that the promise is not returning in time in Edge (the returned ETag is blank). Does anyone have any ideas around this please? I have added async/awaits and Promise.all()... Code extract below.

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">     
        <title>Some Form</title>
        <script src="https://sdk.amazonaws.com/js/aws-sdk-2.410.0.min.js"></script>
        <script type="text/javascript">
            // See the Configuring section to configure credentials in the SDK
            // Configure your region
            AWS.config.region = 'us-west-2';
            var IdentityPoolId = "";
            AWS.config.credentials = new AWS.CognitoIdentityCredentials({
                IdentityPoolId: IdentityPoolId
            });

            AWS.config.credentials.get(function(err) {
                if (err) alert(err);
                console.log(AWS.config.credentials);
            });
            var s3 = new AWS.S3({apiVersion: '2006-03-01', region: 'us-west-2'});
          </script>
        <script type='text/javascript'>            
            
            // Upload a list of files to an S3 bucket
            var putBatch = async function putBatch(bucket, key, files) {
                // Make all the putObject calls immediately
                // Will return rejected promise if any requests fail
                return await Promise.all(Array.from(files).map(function(file) {
                    var ukey = key + file.name;
                    var params = {
                        Bucket: bucket,
                        Key: ukey,
                        Body: file
                    };
                    var response = s3.putObject(params).promise();
                    return response;
                }));
            };
            const validateUploadForm = async () =>
            {
                var uploadedFiles = document.getElementById("files").files;

                if (!uploadedFiles.length) {                 
                    alert("A file must be selected!");
                } else 
                {
                    var test = getDate();
                    try {                        
                        var bucket = '';
                        var objectKey = '';
                        await putBatch(bucket, objectKey, uploadedFiles)
                        .then(alert("Successfully uploaded file."))
                        .catch(console.error.bind(console));
                    } catch (e) {
                        console.log(e);
                    }
                    self.close();
                }
            };

        </script>
    </head>
    <body>
        <text id="title" name="title">
        <form id="someForm" name="someForm" >
        <p>Try selecting more than one file when browsing for files.</p>
        <p>Click on the "Choose Files" button to upload:</p>            
        <form id='uploadForm' name='uploadForm'>
            <CENTER>
            <label for="files">Select file(s):</label>
            <input onchange="uploadCheck()" type="file" id="files" multiple>
            <button id="get-data">Get</button>
            </CENTER>
        </form>
        <script>
            // Add click event listener to the button
            const button = document.getElementById('get-data');
            button.addEventListener('click', async () => {
                // Call the asynchronous function
                const data = await validateUploadForm();
            });
        </script>
    </body>
</html>
tj_aeo
asked 5 months ago147 views
1 Answer
0

Hi there,

Note that SDK-JAVA is an open-source product that interacts with AWS Services and it is developed and maintained by a small group of developers. Please kindly note that given the issue is about working SDK code's performance issue with third party platform MS-Edge browser, I am providing suggestions on best effort basis.

To understand what exactly was going on with the Edge browser, more logs is required, it appears that you are using SDK-2: Logging and Debugging: https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/logging-slf4j.html

Once you can see unexpected errors/warnings, debug accordingly. If conclude that the issue is not about Edge browser and is about aws-sdk-java-v2 itself, reaching out to SDK-JAVA community via GitHub https://github.com/aws/aws-sdk-java-v2/issues allows a direct and transparent communication. Alternatively, you may post error logs here for Re:post community assistance, please kindly note that making sure no sensitive/confidential information is included in posted logs.

AWS
answered 4 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions