-
Notifications
You must be signed in to change notification settings - Fork 634
Closed
Labels
bugThis issue is a bug.This issue is a bug.closed-for-stalenessp2This is a standard priority issueThis is a standard priority issueresponse-requestedWaiting on additional info and feedback. Will move to \"closing-soon\" in 7 days.Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days.
Description
Checkboxes for prior research
- I've gone through Developer Guide and API reference
- I've checked AWS Forums and StackOverflow.
- I've searched for previous similar issues and didn't find any solution.
Describe the bug
Regression Issue
- Select this option if this issue appears to be a regression.
SDK version number
"@aws-sdk/client-s3": "^3.654.0"
Which JavaScript Runtime is this issue in?
Node.js
Details of the browser/Node.js/ReactNative version
v20.14.0
Reproduction Steps
Following is the code snippet for UPLOAD FILES in S3 Bucket from client side:
import { S3Client, PutObjectCommand } from "@aws-sdk/client-s3";
export const uploadFileToS3 = async (
file: File,
accessKey: string,
secretKey: string,
handleProgress: (progress: number) => void
): Promise<{ src: string }> => {
const s3 = new S3Client({
credentials: {
accessKeyId: accessKey,
secretAccessKey: secretKey,
},
region: process.env.BUCKET_REGION,
});
return new Promise(async (resolve, reject) => {
try {
const contentType = file.type;
// Read the file as a stream
const reader = file.stream().getReader();
const fileStream = createProgressStream(file, handleProgress);
// Create the S3 upload parameters
const params = {
Bucket: process.env.BUCKET_NAME,
Key: file.name,
Body: new Response(fileStream).body,
ContentType: contentType,
ACL: "public-read",
};
const command = new PutObjectCommand(params);
// Send the command to S3
await s3.send(command);
resolve({
src: `https://${params.Bucket}.s3.${s3.config.region}.amazonaws.com/${params.Key}`,
});
} catch (error) {
reject(error);
}
});
};
// Helper function to track the progress
const createProgressStream = (
file: File,
handleProgress: (progress: number) => void
) => {
const fileSize = file.size;
let uploaded = 0;
const reader = file.stream().getReader();
return new ReadableStream({
async start(controller) {
handleProgress(0); // Initially 0%
},
async pull(controller) {
const chunk = await reader.read();
if (chunk.done) {
controller.close();
return;
}
uploaded += chunk.value.length;
const progressPercentage = Math.round((uploaded / fileSize) * 100);
handleProgress(progressPercentage);
controller.enqueue(chunk.value);
},
});
};
Observed Behavior
When the s3 upload api is getting called, it is giving this error in its status in network tab status. I was implementing this with next js.
net::ERR_H2_OR_QUIC_REQUIRED
Expected Behavior
It should upload the file and return back the resolved url of S3.
Possible Solution
No response
Additional Information/Context
No response
Metadata
Metadata
Assignees
Labels
bugThis issue is a bug.This issue is a bug.closed-for-stalenessp2This is a standard priority issueThis is a standard priority issueresponse-requestedWaiting on additional info and feedback. Will move to \"closing-soon\" in 7 days.Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days.