Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convenience function to make private files public #4325

Closed
ajhool opened this issue Nov 1, 2019 · 6 comments
Closed

Convenience function to make private files public #4325

ajhool opened this issue Nov 1, 2019 · 6 comments
Labels
feature-request Request a new feature Storage Related to Storage components/category

Comments

@ajhool
Copy link

ajhool commented Nov 1, 2019

Is your feature request related to a problem? Please describe.
A common use-case is to have private files that are "published" and made to be public.

Describe the solution you'd like
I think the simplest way to do this with the aws-sdk is a client-side call to s3.copyObject where (altough, this would not gracefully handle interruptions). If these functions were added to Storage, the methods might be:

// pseudocode
makePublic(keys: string | string[]) {
   // convert single keys to an array
   const toMakePublic = [].concat(keys);
   const reqs = toMakePublic.map(item => ({
        Bucket: Storage.Bucket, 
        CopySource: path(Storage.Bucket, 'private', userId, prefix, key), 
        Key: path('public', userId, prefix, key)
   })

   for(r in reqs) {
     await s3.copyObject(r)
   }

   // Maybe add a delete flag that would delete the files from the private paths if the copy is a success.
}
```

**Describe alternatives you've considered**
Relying on secretive key names and disabling "list" to implement a private access pattern within the public bucket.

**Additional context**
@ajhool ajhool added the feature-request Request a new feature label Nov 1, 2019
@jordanranz jordanranz added the Storage Related to Storage components/category label Nov 1, 2019
@sammartinez
Copy link
Contributor

@ajhool Do you have an example of this working out in the world? It seems like if an image/file is set to private, there would be a reason for this correct? Just want a little more context for this is all. Thanks ahead of time!

@ajhool
Copy link
Author

ajhool commented Nov 21, 2019

Oftentimes in applications a file will go through a "Draft" stage before a "Publish" phase.

For instance, a text document might be stored as a text file before it is finally published (see, medium.com). That would be a private -> public transition.

Or a photo sharing website might have private photos that you can choose to share with friends or choose to make public.

In my specific application, users have photo albums that are almost always private; but there is a feature that allows the user to "publish" their photo album so that the general public can rate the photos in the album. That would be a transition from private to public.

@undefobj
Copy link
Contributor

This sounds like a valid use case, there are two ways to accomplish this:

  1. Have the administrator move the files on the backend, this can be done via Lambda functions orchestrated with the Amplify CLI. In some ways this is similar to the new Cognito Admin functionality recently added
  2. Do it from the client, in which case there is still a "copy" action behind the scenes where the client fetches it's content and puts it in the new location, at which point it then deletes the old item to ensure data integrity. There's a similar moveTo command in .Net SDK: https://docs.aws.amazon.com/sdkfornet1/latest/apidocs/html/M_Amazon_S3_IO_S3FileInfo_MoveTo_2.htm

If we did this, I would imagine that it should be a generic Storage.move(source, destination|fileLevel) which would allow private->public, public->private, private->protected, etc.

For the time being this is possible using the existing Storage APIs but lets leave this issue open to get some feedback for future work.

@arelaxend
Copy link

Up!

@renebrandel
Copy link

hi folks! You can now accomplish this via the Storage.copy(...) command. More details here: https://twitter.com/renebrandel/status/1405915684781977604

@github-actions
Copy link

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels or Discussions for those types of questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request a new feature Storage Related to Storage components/category
Projects
None yet
Development

No branches or pull requests

6 participants