Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

After Migrating Angular to the new build system @aws-sdk/lib-storage Upload is not working any more

Tags:

angular

vite

I am trying to upload images to AWS but because of the Migrating to the new build system it is not working anymore

import { Upload } from "@aws-sdk/lib-storage";
import { S3Client } from "@aws-sdk/client-s3";

const parallelUploads3 = new Upload({
client: new S3Client({}),
params: { Bucket, Key, Body },
});
parallelUploads3.on("httpUploadProgress", (progress) => {
console.log(progress);
});

parallelUploads3.done().then(
(data) => {
console.log(data)
},
(err: any) => {
console.log(err)
},
);

and i get this Error

TypeError: Cannot read properties of undefined (reading 'done')
    at getChunkStream.js:5:5
    at Generator.next (<anonymous>)
    at resume (chunk-CDW57LCT.js?v=b9e9dd30:100:27)
    at chunk-CDW57LCT.js?v=b9e9dd30:106:63
    at new ZoneAwarePromise (zone.js:1425:21)
    at it.<computed> [as next] (chunk-CDW57LCT.js?v=b9e9dd30:106:38)
    at Upload.<anonymous> (Upload.js:130:9)
    at Generator.next (<anonymous>)
    at chunk-CDW57LCT.js?v=b9e9dd30:90:61
    at new ZoneAwarePromise (zone.js:1425:21)

I expect the Migrating should have no effect on the app

like image 640
Mohamed Zakaria Avatar asked Feb 04 '26 15:02

Mohamed Zakaria


1 Answers

i'm searching for the solution as well. but if your file is not large (less than 2G) based on my test, you can try transform the file to uint8Array first as a workaround

  const arrayBuffer = await file.arrayBuffer();
  const uint8Array = new Uint8Array(arrayBuffer);
  const upload = new Upload({
    client: s3Client,
    params: { Bucket: bucket, Key: path, Body: uint8Array },
  });
like image 80
kloc Avatar answered Feb 06 '26 07:02

kloc