10

I uploaded a large file to gitub using Git LFS (Large file storage).

At first I could download the file from a direct link.

raw.githubusercontent.com/userName/reposiotry/master/file.mp4

But on the next day the file began to contain a text value

oid sha256:59f24bc922e1a48bb3feeba18b23f0e9622a7ee07166d925650d7a933283f8b1
size 123882252

How do I download this file ? How to get a direct link to it ?

mkrieger1
  • 10,793
  • 4
  • 39
  • 47
I.U.
  • 121
  • 1
  • 5

3 Answers3

2

Quote from this article,

Storage quota

If you use more than 1 GB of storage without purchasing a data pack, you can still clone repositories with large assets, but you will only retrieve the pointer files, and you will not be able to push new files back up.

I am assuming you have not purchased any additional storage for git lfs on GitHub. As you said that initially you were able to access it via this link : http://raw.githubusercontent.com/userName/reposiotry/master/file.mp4

I am guessing that you uploaded more such files which caused you to exceed your storage quota i.e 1 GB. As pointed by the article above, you will only retrieve the pointer files once you exceed the quota.

You can check if you have exceeded the limit of your storage quota here, https://github.com/settings/billing

However, if my assumptions are wrong, then you could try to get the file using this link

https://media.githubusercontent.com/media/user_name/repository_name/branch_name/file_name

Community
  • 1
  • 1
Saurabh P Bhandari
  • 4,338
  • 1
  • 7
  • 34
1

You need to go into the web interface and find the raw link for your file and use that instead.

When you use Git LFS, the file that's actually stored in your repository is a pointer file like the one you see above. GitHub has different URLs to serve raw content for repository contents and Git LFS files, so if you want to get the Git LFS contents, you'll need to use the appropriate link. If you previously had the file as a non-LFS file, then the URL will have changed when you uploaded it again as an LFS file.

Just to note, using those URLs in web pages or otherwise using those direct links as a form of CDN is discouraged.

bk2204
  • 31,903
  • 3
  • 22
  • 39
  • I'll add to this: the pointer that lfs stores on GitHub is into Amazon but you can't access that link directly. When you want a file referenced by a pointer, your computer accesses GitHub and asks for the link. You are given the link along with an access token that will expire. In that way, GitHub can monitor your usage and prevent abuse. – Eyal Dec 21 '19 at 02:31
  • supposedly GitHub uses Amazon pre-signed urls – Kamafeather Oct 29 '20 at 19:57
1

Today I was looking for the same answer, did not found any specific enough to solve the problem, so I was digging on my own and found this:

Assuming that ServerAddres is for example https://api.github.com:

  1. if You konw Your RepoName ('UserName/ReposiotryName' pair) and FileHash,
    then You fetch: ServerAddres + '/repos/RepoName/git/blobs/FileHash'
    and if in response You have:
version https://git-lfs.github.com/spec/v1  
oid sha256:59f24bc922e1a48bb3feeba18b23f0e9622a7ee07166d925650d7a933283f8b1  
size 123882252
  1. than You must search in contents of Your repository for matching FileHash,
    fetching: ServerAddres + '/repos/RepoName/contents'
    and in response You have:
{
  "name": "filename.ext",
  "path": "path/filename.ext",
  "sha": "FileHash",
  "size": 42,
  "url": "https://api.github.com/repos/RepoName/contents/path/filename.ext?ref=master",
  "html_url": "...",
  "git_url": "...",
  "download_url": "...",
  "type": "file",
  "_links": { ... }
}
  1. now You take url value, and fetch it,
    in response You have:
{
  "name": "filename.ext",
  "path": "path/filename.ext",
  "sha": "FileHash",
  "size": 720896,
  "url": "...",
  "html_url": "...",
  "git_url": "...",
  "download_url": "https://media.githubusercontent.com/media/RepoName/RepoHash/path/filename.ext?token=...",
  "type": "file",
  "content": "...", // same as response from pt. 1
  "encoding": "base64",
  "_links": { ... }
}
  1. now You take download_url value, and fetch it,
    in response You should have BINARY file content.

That's it.

NevTon
  • 213
  • 2
  • 12
  • For the filesha in step #2, is it "59f24bc922e1a48bb3feeba18b23f0e9622a7ee07166d925650d7a933283f8b1" in the response of the step #2 – EvanL00 Mar 27 '21 at 10:31
  • No, it is FileHash from step #1. `oid sha256:59f24bc922e1a48bb3feeba18b23f0e9622a7ee07166d925650d7a933283f8b1` is not the identifier that is to be found in the step #2. – NevTon Mar 29 '21 at 08:28
  • Will you method apply to the Git LFS? When you fetch the folder that contains the file, you will get the fileHash and `download_url`. No need to do the step #1 and #2. The problem is that the `download_url` is for the pointer file, not the actual file. – EvanL00 Mar 30 '21 at 07:25
  • Yes, this is exactly why You need to do it like that, if it was simple, it would be done allready by GIT developers. When `download_url` points to pointer file, You need to do this list from step #2 to step #4, step #1 is only here to determine, if it is desired file or pointer file. – NevTon Mar 31 '21 at 14:09
  • Thanks for your reply! I don't quite understand step #2. Does it mean that I need to traverse all the files in my repo to get the matching FileHash? And how do I get this FileHash? For example, the link https:://myrepo.github.com/user/repo/Folder There is a large file in the `Folder`. Step #1, how can I get the `FileHash` for the large file? Step #2, how to find the matching response with the step #1 `FileHash` – EvanL00 Apr 02 '21 at 00:42
  • Ok, I see what You are trying to do, if You get contents of a specific folder, result json format should be same as repository base. You get structure of this folder, where You have files and subfolders. `download_url` can point to file directly, but when you use LFS, all files larger than I think 100KB are pointer files, so, You get this file `url` value `https://api.github.com/repos/RepoName/contents/path/filename.ext` and You need to go from step #3 to step #4 for this specific folder, change `RepoName`, `path` and `filename.ext` accordingly. And no, step #2 is not needed in this case. – NevTon Apr 02 '21 at 12:30
  • FileHash is stored in `sha` key. – NevTon Apr 02 '21 at 12:36