Closed nxia416 closed 1 year ago
for me, the description is not correct: when I upload the file, the file is stored under the protected/{region}:{some_uuid}/
path in my bucket.
However, when getting the URL from Storage.get
function, the return URL suggests a protected/{user_identity_id}/
path.
Is this the problem?
Hi @nxia416 thank you for opening this issue. As described in the docs, you do need to pass the users identity id which will have the format of region:uuid
- however note that this is the Cognito identity id for that user.
Could you tell me more about the ownerId
that you are passing into getS3UrlWithOwner()
? How are you generating this? Also are you able to compare the key to the one in S3 for any discrepancies?
@nadetastic thx for the quick reply. my ownerId
of value e6f903ba-bcc6-4f65-9aed-3bdefd7c8510
is the userId by whom uploaded the file via Storage.put
:
The user-uploaded file is located at:
Here the name is ap-southeast-1:bfc809e1-fe3a-4947-8fab-dce35f2b56d5
, however I don't know how is bfc809e1-fe3a-4947-8fab-dce35f2b56d5
generated, and this UUID is not from my 5 test users.
you mentioned: "the user identity id which will have the format of region:uuid
". Could you give a doc link for the definition of user identity id?
The ap-southweast-1:XXX
id if the users cognito identityId, which you can retrieve in your app using:
const credentials = await Auth.currentCredentials();
const cognitoIdentityId = credentials.identityId;
I'm not certain which id is shown in the User Name field in the cognito view you have screenshoted here.
Links:
@stocaaro Thanks for the help! Now I understand the difference between cognito username (uuid) and identityId (region:new_uuid). One more question about my scenario:
UserA uploaded a file as protected. When UserB login, UserB needs to download the file.
I guess userB needs to provide the userA's identityId for the dowload, right? Is there a way to query userA's identityId by userA's username with Amplify js? Or, the system needs to save userA's identityId to db when uploading?
Correct, userB would need to provide userA's identityId. Cognito doesn't offer an API for looking up other users identityIds. If your application had a list of IdentityIds saved somewhere such is a public Storage location or in AppSync where other users could discover a list of identity ids, then it would be possible to use those identityIds to list protected objects saved by those other users.
Somewhat related to this topic, the team recently published an RFC that includes having Storage return values follow a strict StorageObjectReference
structure that will include all the referential information needed to look the file up again later, such as the identityId. In my application development, these are the details I'll save to an external store, like AppSync, to make it easy to share/access these files again later.
Hi @nxia416 wanted to following up here 🙂 - did you have any other questions regarding this issue?
@nxia416 Closing this issue out - let me know if you still have questions about this.
Somewhat related to this topic, the team recently published an RFC that includes having Storage return values follow a strict
StorageObjectReference
structure that will include all the referential information needed to look the file up again later, such as the identityId. In my application development, these are the details I'll save to an external store, like AppSync, to make it easy to share/access these files again later.
Hi @stocaaro, quick question about this: I'm trying to understand AppSync's function here -- would I be using it to connect to say a DynamoDB table, or an S3 bucket to store the identityId mappings? Alternatively, would it be considered okay practice to save the identityId as a custom attribute to the Cognito user?
Hello @kulikowska,
Each users identity id is vended from Cognito. You can access it using the Amplify Auth category like this:
const credentials = await Auth.currentUserCredentials();
console.log("identityId", credentials.identityId);
I'm not aware of a way to store and lookup other users identity ids through Auth.
My recommendation to look at something like AppSync would be to use AppSync to keep an external to S3 index that associates protected files with the user identity who uploaded them so that other users might retrieve these files.
Thanks, Aaron
@stocaaro I was having the same problem, but actually the problem doesn't exist, because for the current user you can omit the identityId field as seen in @nxia416 's screenshot there is an automatic association with the current user and by omitting the field you reach the protected level
Before opening, please confirm:
JavaScript Framework
Next.js
Amplify APIs
GraphQL API
Amplify Categories
storage
Environment information
Describe the bug
userA uploads a file with the s3download funtion, and userB need to download it with the getS3UrlWithOwner function. However the is a XML fragment saying "The specified key does not exist."
Expected behavior
I expect the uploaded file could be shared by both userA and userB.
Reproduction steps
NoSuchKey
Code Snippet
Log output
aws-exports.js
Manual configuration
No response
Additional configuration
No response
Mobile Device
No response
Mobile Operating System
No response
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
No response