arc
arc copied to clipboard
Proposal: add `get` or `fetch` to storage
Currently the storage expects a url
function to generate the URL which points to the uploaded file. However, there is no way to fetch an asset from the uploaded location. Once the asset has been uploaded, there is no way to get the asset from the storage location again.
An example of when this would be convenient is proxying requests. For example if you want to do some sort of permission check before allowing a user to download a file. You can do this on S3 with signed urls, but sometimes that is not desirable. Perhaps you wish to serve the content over a different protocol (such as a [web]socket.) In this case it would be nice if there was a convenient function to read the asset into memory from the storage location.
If this is something that you think is a good fit for the project then I can take a look at implementing it.
If you want to get
stuff from S3, you can drop to erlcloud_s3
and use:
:erlcloud_s3.configure('KEY', SECRET')
:erlcloud_s3.get_object('BUCKET', 'PATH')
@oarrabi thanks. I am aware you can bypass arc. I was thinking it would be helpful to define it on the storage in the same way you can for put
or url
.
I was a little surprised at the lack of a "retrieve" function as well (also using S3). Arc has a lot of out-of-the-box defaults for how to name files, creating the appropriate paths, etc, and they are not completely obvious to reproduce manually, splitting "bucket" and "path", particularly when dealing with "variants" (thumbnails, et al). It would be cleanest to have an Arc-based function to retrieve data, using all the same path constructions as used for storage, and particularly because storage could be configured to be local OR S3, if the retrieval functions are aware of that configuration, they can "do the right thing".
I just started using arc and would love this functionality as well. I currently use ExAws
directly to accomplish this but would be nice to have this done in arc.
I will see if I can put up a PR for this.
Hi, @mayppong do you use ExAws.S3.download_file / ExAws.S3.get_object ?
Yes, I am.
+1