Serve git-lfs files from express' public folder
Actually the pointer
file doesn't contain any url information in it (as can be seen in the link you provided, or here) - it just keeps the oid
(Object ID) for the blob which is just its sha256
.
You can however achieve what you're looking for using the oid
and the lfs api that allows you to download specific oid
s using the batch request.
You can tell what is the endpoint that's used to store your blobs from .git/config
which can accept non-default lfsurl
tags such as:
[remote "origin"] url = https://... fetch = +refs/heads/*:refs/remotes/origin/* lfsurl = "https://..."
or a separate
[lfs] url = "https://..."
If there's no lfsurl
tag then you're using GitHub's endpoint (which may in turn redirect to S3):
Git remote: https://git-server.com/user/repo.gitGit LFS endpoint: https://git-server.com/user/repo.git/info/lfsGit remote: git@git-server.com:user/repo.gitGit LFS endpoint: https://git-server.com/user/repo.git/info/lfs
But you should work against it and not S3 directly, as GitHub's redirect response will probably contain some authentication information as well.
Check the batch response doc to see the response structure - you will basically need to parse the relevant parts and make your own call to retrieve the blobs (which is what git lfs
would've done in your stead during checkout).
A typical response (taken from the doc I referenced) would look something like:
{ "_links": { "download": { "href": "https://storage-server.com/OID", "header": { "Authorization": "Basic ...", } } }}
So you would GET
https://storage-server.com/OID
with whatever headers
was returned from the batch response - the last step will be to rename the blob that was returned (it's name will typically be just the oid
as git lfs uses checksum based storage) - the pointer file has the original resource's name so just rename the blob to that.
I've finally made a middleware for this: express-lfs with a demo here: https://expresslfs.herokuapp.com
There you can download a 400Mo file as a proof.
See usage here: https://github.com/goodenough/express-lfs#usage
PS: Thanks to @fundeldman for good advices in his answer ;)