Getting data back from Async function in NextJS
Richard
Posted on July 15, 2022
I have the following code in /lib/s3libdata.js
:
import { Upload } from "@aws-sdk/lib-storage";
import {S3, S3Client} from "@aws-sdk/client-s3";
export const putObject = async (uploadFilePath, fileStream) => {
const upload = new Upload({
params: {
Bucket: process.env.AWS_BUCKET,
Key: uploadFilePath,
Body: fileStream,
},
client: new S3Client({
region: process.env.AWS_REGION,
credentials: {
accessKeyId: process.env.AWS_ACCESS_KEY,
secretAccessKey: process.env.AWS_SECRET_KEY,
},
}),
queueSize: 3,
});
upload.on("httpUploadProgress", (progress) => {
console.log(progress);
});
await upload.done();
};
Using the @aws-sdk/lib-storage
. The upload works, and in my terminal I get the console log output of the progress. My question now is how do I send that progress information back to the page?
The way I call this is from /pages/api/upload.js
which is called from /pages/upload.js
.
Ideally I want the upload.js page to display the progress data. How can I achieve this?
💖 💪 🙅 🚩
Richard
Posted on July 15, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
javascript Understanding the 'use client' Directive in Next.js: Client-Side Components Explained
October 24, 2024
javascript Fix: Hydration failed because the initial UI does not match what was rendered on the server
March 13, 2024