Skip to content

file size affecting upload order when uploading array of files/images to s3 - NextJS #5308

Answered by ajredniwja
hampak asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @hampak map is not waiting for uploadImages. You can try something like this:

const uploadImages = async(file) => {
    const imageName = randomBytes(16).toString("hex")

    const command = new PutObjectCommand({
        Bucket: process.env.AWS_BUCKET_NAME,
        Key: imageName,
        ContentType: file.type
    })

    const preSignedUrl = await getSignedUrl(client, command, {
        expiresIn: 1000
    })

    const upload = await fetch(preSignedUrl, {
        method: "PUT",
        body: file,
        headers: { "Content-Type": file.type }
    })

    if (upload.ok) return new Response("OK")
};

const uploadAllImages = async(photosImagesArray) => {
    for (let i = 0; i < phot…

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
3 replies
@github-actions
Comment options

@hampak
Comment options

@hampak
Comment options

Answer selected by hampak
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
guidance General information and guidance, answers to FAQs, or recommended best practices/resources. response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days. attention This discussion needs attention
2 participants