aws-amplify / amplify-js

A declarative JavaScript library for application development using cloud services.
https://docs.amplify.aws/lib/q/platform/js
Apache License 2.0
9.45k stars 2.13k forks source link

S3 has a different identity id than cognito user id #13579

Open juri-diener opened 5 months ago

juri-diener commented 5 months ago

Environment information

npm ERR! could not determine executable to run

npm ERR! A complete log of this run can be found in: /Users/.../.npm/_logs/2024-07-03T19_02_20_332Z-debug-0.log

Description

I have problems that the S3 identity id is completely different from the cognito userId. Although it says in the docs that the cognito userId is used.

User with the Id: 70fc.......a6fb uploads the file in S3 the file now ends up under: bucketname/eu-north-1:be14......36aaa70/audio/filename

Where does this id come from? eu-north-1:be14......36aaa70 I kinda remember that I saw this id especially the end aaa70 but this was I think in my test project kinda, but then I created a new one. But I'm not sure. How to find where this id comes from???

And how the uploadData function knows who is uploading the file? Please help to figure it out. This really stopping me to get to production with my app.

This is the code for uploading the file? Do I do something wrong?

export const uploadFile = async (
  fileUri: string,
  filename: string = "",
  setProgress: React.Dispatch<React.SetStateAction<number>>,
) => {
  const file = await getBlob(fileUri);
  const fileNameKey = filename ? filename : uuid();
  let result;

  const fileExt = fileUri.split(".").pop();
  const userId = userStrore.getState().id;

  let folder = "images";
  if (fileExt === "m4a") {
    folder = "audio";
  }

  try {
    result = await uploadData({
      key: `${folder}/${fileNameKey}.${fileExt}`,
      data: file,
      options: {
        accessLevel: "protected",
        onProgress: ({ transferredBytes, totalBytes }) => {
          if (totalBytes) {
            const total = Math.round((transferredBytes / totalBytes) * 100);
            setProgress(Number(total));
          }
        },
      },
    }).result;
  } catch (error) {
    console.warn("Error : ", error);
  }
  return result?.key;
};
ykethan commented 4 months ago

Hey,👋 thanks for raising this! I'm going to transfer this over to our JS repository for better assistance 🙂