How could i get a permanent link for raw file? #22537
-
I am searching google for about 3 hours and stil not succeed in this. |
Beta Was this translation helpful? Give feedback.
Replies: 13 comments 7 replies
-
HI @Lotaristo, a worked example for you using a PUBLIC repository, please note you SHOULD use the same URL format for a PRVATE repository and cannot use the short lived expiring token shown in the browser session passed as a query parameter but will need to create a personal access token with permissions. GitHub file in browser RAW format URL
If your repository file is a PRIVATE visibility repository you will need to pass a personal access token with scope permission to READ from the repository in an authentication header by adding
If unsure how to get a personal access token see this link creating-a-personal-access-token, In my example variable $MT+PAT holds the personal teh value of my personal access token previously created so you full format will like
This will be the solution to your question. |
Beta Was this translation helpful? Give feedback.
-
Well, public worked well for me, thanks! |
Beta Was this translation helpful? Give feedback.
-
is there a way for private repo? |
Beta Was this translation helpful? Give feedback.
-
Doers not work even for public files, just a 404 error. |
Beta Was this translation helpful? Give feedback.
-
If you remove /blob it works |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
I'm needing help with this exact issue. For private, the raw URL keeps changing. I'd need something like a static raw URL. |
Beta Was this translation helpful? Give feedback.
-
Hello, has anybody found a soultion for this |
Beta Was this translation helpful? Give feedback.
-
For those who are still looking for the answer, hope this helps. Since the tokens that are used to access raw downloads rotate regularly for security you'll need to authenticate your requests. I'd recommend using the get repository content REST API endpoint with a personal access token. This will return a json object with a fresh download_url each time that will retrieve the file. curl -L Where '[organization]' can be your enterprise organization handle or you can replace it with your personal handle and '[repository]' is the repository name where the file is stored. '[TOKEN]' - is your personal access token. After you have created it you have to provide authorization to be used against your organization, if needed. You can try using Postman to test the GET API call for retrieving the contents of the file and the 'download_url'. Thanks, |
Beta Was this translation helpful? Give feedback.
-
PAT is not a good solution since it gives access to all files in repo, but I need to give access to just one file (considered non-confidential) by constant URL. Even fine-grained tokens do not provide any mechanism to restrict access by file or path. |
Beta Was this translation helpful? Give feedback.
-
This is disappointing; raw should be exactly that, raw... |
Beta Was this translation helpful? Give feedback.
-
I was expecting the .netrc to put in my token where it's needed. But the Authorization header needs to be in place. For this, I need scripting. :-/ |
Beta Was this translation helpful? Give feedback.
-
I am facing the same issue with a private repository. In my case, I have a portfolio that retrieves data from the GitHub API, and I'm able to successfully fetch the README, about section, languages, etc. The main issue arises when dealing with images, such as logos or mockups, that are stored in the repositories. Using the GitHub API, I can retrieve a Here's a sample of the code I'm using: const octokit = new Octokit({
auth: getSecret("GITHUB_ACCESS_TOKEN"),
})
async function getRepoAsset(repoUrl:string, assetUrl: string) {
try {
const { data } = await octokit.request(`GET ${repoUrl}/contents/${assetUrl}`, {
owner: 'OWNER',
repo: 'REPO',
path: 'PATH',
headers: {
'accept': 'application/vnd.github.object+json',
'X-GitHub-Api-Version': '2022-11-28'
}
})
return data.download_url;
} catch (error) {
console.error(error);
}
} Is there a way to obtain a URL that doesn't expire or another solution to serve these images indefinitely in a production environment, without downloading and saving the images? Doing so defeats the purpose of having the images in the repository, as I might as well just store the images in services like S3 and store those URLs directly in the README. Thanks in advance for any advice you can share! |
Beta Was this translation helpful? Give feedback.
HI @Lotaristo,
a worked example for you using a PUBLIC repository, please note you SHOULD use the same URL format for a PRVATE repository and cannot use the short lived expiring token shown in the browser session passed as a query parameter but will need to create a personal access token with permissions.
GitHub file in browser
RAW format URL
If your repository file is a PRIVATE visibility repository you will need to pass a personal access token with scope permission to READ from the repository in an authentication header by ad…