import{_ as a}from"./chunks/PageInfo.vue_vue_type_script_setup_true_lang.250b3e56.js";import{_ as e,o as l,c as o,H as p,k as s,a as r,Q as c}from"./chunks/framework.b7580407.js";import"./chunks/commonjsHelpers.725317a4.js";const C=JSON.parse('{"title":"Configure rclone for R2","description":"","frontmatter":{},"headers":[],"relativePath":"development/rclone-for-r2.md","filePath":"development/rclone-for-r2.md","lastUpdated":1710267506000}'),t={name:"development/rclone-for-r2.md"},i=s("h1",{id:"configure-rclone-for-r2",tabindex:"-1"},[r("Configure rclone for R2 "),s("a",{class:"header-anchor",href:"#configure-rclone-for-r2","aria-label":'Permalink to "Configure rclone for R2"'},"​")],-1),y=c(`<p>Example of how to configure <code>rclone</code> to use R2.</p><p>You must <a href="https://developers.cloudflare.com/r2/data-access/s3-api/tokens/" target="_blank" rel="noreferrer">generate an Access Key</a> before getting started. All examples will utilize <code>access_key_id</code> and <code>access_key_secret</code> variables which represent the <strong>Access Key ID</strong> and <strong>Secret Access Key</strong> values you generated.</p><p>With <a href="https://rclone.org/install/" target="_blank" rel="noreferrer"><code>rclone</code></a> installed, you may run <a href="https://rclone.org/s3/" target="_blank" rel="noreferrer"><code>rclone config</code></a> to configure a new S3 storage provider. You will be prompted with a series of questions for the new prvider details.</p><p>If you have already configured <code>rclone</code> in the past, you may run <code>rclone config file</code> to print the location of your <code>rclone</code> configuration file:</p><div class="language-bash vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki github-dark-dimmed vp-code-dark"><code><span class="line"><span style="color:#F69D50;">$</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">rclone</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">config</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">file</span></span>
<span class="line"><span style="color:#768390;"># Configuration file is stored at:</span></span>
<span class="line"><span style="color:#768390;"># ~/.config/rclone/rclone.conf</span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#6F42C1;">$</span><span style="color:#24292E;"> </span><span style="color:#032F62;">rclone</span><span style="color:#24292E;"> </span><span style="color:#032F62;">config</span><span style="color:#24292E;"> </span><span style="color:#032F62;">file</span></span>
<span class="line"><span style="color:#6A737D;"># Configuration file is stored at:</span></span>
<span class="line"><span style="color:#6A737D;"># ~/.config/rclone/rclone.conf</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p>Then use an editor (<code>nano</code> or <code>vim</code>, for example) to add or edit the new provider. This example assumes you are adding a new <code>r2demo</code> provider:</p><div class="language-bash vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki github-dark-dimmed vp-code-dark"><code><span class="line"><span style="color:#ADBAC7;">[r2]</span></span>
<span class="line"><span style="color:#6CB6FF;">type</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">s3</span></span>
<span class="line"><span style="color:#F69D50;">provider</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">Cloudflare</span></span>
<span class="line"><span style="color:#F69D50;">access_key_id</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">abc123</span><span style="color:#ADBAC7;"> </span><span style="color:#768390;"># Your access_key_id</span></span>
<span class="line"><span style="color:#F69D50;">secret_access_key</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">xyz456</span><span style="color:#ADBAC7;"> </span><span style="color:#768390;"># Your access_key_secret</span></span>
<span class="line"><span style="color:#F69D50;">endpoint</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">https://</span><span style="color:#F47067;">&lt;</span><span style="color:#96D0FF;">accounti</span><span style="color:#ADBAC7;">d</span><span style="color:#F47067;">&gt;</span><span style="color:#96D0FF;">.r2.cloudflarestorage.com</span></span>
<span class="line"><span style="color:#F69D50;">acl</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">private</span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#24292E;">[r2]</span></span>
<span class="line"><span style="color:#005CC5;">type</span><span style="color:#24292E;"> </span><span style="color:#032F62;">=</span><span style="color:#24292E;"> </span><span style="color:#032F62;">s3</span></span>
<span class="line"><span style="color:#6F42C1;">provider</span><span style="color:#24292E;"> </span><span style="color:#032F62;">=</span><span style="color:#24292E;"> </span><span style="color:#032F62;">Cloudflare</span></span>
<span class="line"><span style="color:#6F42C1;">access_key_id</span><span style="color:#24292E;"> </span><span style="color:#032F62;">=</span><span style="color:#24292E;"> </span><span style="color:#032F62;">abc123</span><span style="color:#24292E;"> </span><span style="color:#6A737D;"># Your access_key_id</span></span>
<span class="line"><span style="color:#6F42C1;">secret_access_key</span><span style="color:#24292E;"> </span><span style="color:#032F62;">=</span><span style="color:#24292E;"> </span><span style="color:#032F62;">xyz456</span><span style="color:#24292E;"> </span><span style="color:#6A737D;"># Your access_key_secret</span></span>
<span class="line"><span style="color:#6F42C1;">endpoint</span><span style="color:#24292E;"> </span><span style="color:#032F62;">=</span><span style="color:#24292E;"> </span><span style="color:#032F62;">https://</span><span style="color:#D73A49;">&lt;</span><span style="color:#032F62;">accounti</span><span style="color:#24292E;">d</span><span style="color:#D73A49;">&gt;</span><span style="color:#032F62;">.r2.cloudflarestorage.com</span></span>
<span class="line"><span style="color:#6F42C1;">acl</span><span style="color:#24292E;"> </span><span style="color:#032F62;">=</span><span style="color:#24292E;"> </span><span style="color:#032F62;">private</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><p>You may then use the new <code>rclone</code> provider for any of your normal workflows.</p><h2 id="list-buckets-objects" tabindex="-1">List buckets &amp; objects <a class="header-anchor" href="#list-buckets-objects" aria-label="Permalink to &quot;List buckets &amp; objects&quot;">​</a></h2><p>The <a href="https://rclone.org/commands/rclone_tree/" target="_blank" rel="noreferrer">rclone tree</a> command can be used to list the contents of the remote, in this case Cloudflare R2.</p><div class="language-bash vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki github-dark-dimmed vp-code-dark"><code><span class="line"><span style="color:#F69D50;">$</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">rclone</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">tree</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">r2demo:</span></span>
<span class="line"><span style="color:#768390;"># /</span></span>
<span class="line"><span style="color:#768390;"># ├── user-uploads</span></span>
<span class="line"><span style="color:#768390;"># │   └── foobar.png</span></span>
<span class="line"><span style="color:#768390;"># └── my-bucket-name</span></span>
<span class="line"><span style="color:#768390;">#     ├── cat.png</span></span>
<span class="line"><span style="color:#768390;">#     └── todos.txt</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F69D50;">$</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">rclone</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">tree</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">r2demo:my-bucket-name</span></span>
<span class="line"><span style="color:#768390;"># /</span></span>
<span class="line"><span style="color:#768390;"># ├── cat.png</span></span>
<span class="line"><span style="color:#768390;"># └── todos.txt</span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#6F42C1;">$</span><span style="color:#24292E;"> </span><span style="color:#032F62;">rclone</span><span style="color:#24292E;"> </span><span style="color:#032F62;">tree</span><span style="color:#24292E;"> </span><span style="color:#032F62;">r2demo:</span></span>
<span class="line"><span style="color:#6A737D;"># /</span></span>
<span class="line"><span style="color:#6A737D;"># ├── user-uploads</span></span>
<span class="line"><span style="color:#6A737D;"># │   └── foobar.png</span></span>
<span class="line"><span style="color:#6A737D;"># └── my-bucket-name</span></span>
<span class="line"><span style="color:#6A737D;">#     ├── cat.png</span></span>
<span class="line"><span style="color:#6A737D;">#     └── todos.txt</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6F42C1;">$</span><span style="color:#24292E;"> </span><span style="color:#032F62;">rclone</span><span style="color:#24292E;"> </span><span style="color:#032F62;">tree</span><span style="color:#24292E;"> </span><span style="color:#032F62;">r2demo:my-bucket-name</span></span>
<span class="line"><span style="color:#6A737D;"># /</span></span>
<span class="line"><span style="color:#6A737D;"># ├── cat.png</span></span>
<span class="line"><span style="color:#6A737D;"># └── todos.txt</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br></div></div><h2 id="upload-and-retrieve-objects" tabindex="-1">Upload and retrieve objects <a class="header-anchor" href="#upload-and-retrieve-objects" aria-label="Permalink to &quot;Upload and retrieve objects&quot;">​</a></h2><p>The <a href="https://rclone.org/commands/rclone_copy/" target="_blank" rel="noreferrer">rclone copy</a> command can be used to upload objects to an R2 bucket and vice versa - this allows you to upload files up to the 5 TB maximum object size that R2 supports.</p><div class="language-bash vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki github-dark-dimmed vp-code-dark"><code><span class="line"><span style="color:#768390;"># Upload dog.txt to the user-uploads bucket</span></span>
<span class="line"><span style="color:#F69D50;">$</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">rclone</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">copy</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">dog.txt</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">r2demo:user-uploads/dog.txt</span></span>
<span class="line"><span style="color:#F69D50;">$</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">rclone</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">tree</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">r2demo:user-uploads</span></span>
<span class="line"><span style="color:#768390;"># /</span></span>
<span class="line"><span style="color:#768390;"># ├── foobar.png</span></span>
<span class="line"><span style="color:#768390;"># └── dog.txt</span></span>
<span class="line"></span>
<span class="line"><span style="color:#768390;"># Download dog.txt from the user-uploads bucket</span></span>
<span class="line"><span style="color:#F69D50;">$</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">rclone</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">copy</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">r2demo:user-uploads/dog.txt</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">dog.txt</span></span></code></pre><pre class="shiki github-light vp-code-light"><code><span class="line"><span style="color:#6A737D;"># Upload dog.txt to the user-uploads bucket</span></span>
<span class="line"><span style="color:#6F42C1;">$</span><span style="color:#24292E;"> </span><span style="color:#032F62;">rclone</span><span style="color:#24292E;"> </span><span style="color:#032F62;">copy</span><span style="color:#24292E;"> </span><span style="color:#032F62;">dog.txt</span><span style="color:#24292E;"> </span><span style="color:#032F62;">r2demo:user-uploads/dog.txt</span></span>
<span class="line"><span style="color:#6F42C1;">$</span><span style="color:#24292E;"> </span><span style="color:#032F62;">rclone</span><span style="color:#24292E;"> </span><span style="color:#032F62;">tree</span><span style="color:#24292E;"> </span><span style="color:#032F62;">r2demo:user-uploads</span></span>
<span class="line"><span style="color:#6A737D;"># /</span></span>
<span class="line"><span style="color:#6A737D;"># ├── foobar.png</span></span>
<span class="line"><span style="color:#6A737D;"># └── dog.txt</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D;"># Download dog.txt from the user-uploads bucket</span></span>
<span class="line"><span style="color:#6F42C1;">$</span><span style="color:#24292E;"> </span><span style="color:#032F62;">rclone</span><span style="color:#24292E;"> </span><span style="color:#032F62;">copy</span><span style="color:#24292E;"> </span><span style="color:#032F62;">r2demo:user-uploads/dog.txt</span><span style="color:#24292E;"> </span><span style="color:#032F62;">dog.txt</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br></div></div><h2 id="generate-presigned-urls" tabindex="-1">Generate presigned URLs <a class="header-anchor" href="#generate-presigned-urls" aria-label="Permalink to &quot;Generate presigned URLs&quot;">​</a></h2><p>You can also generate presigned links which allow you to share public access to a file temporarily using the <a href="https://rclone.org/commands/rclone_link/" target="_blank" rel="noreferrer">rclone link</a> command.</p>`,16);function d(u,b,m,F,h,D){const n=a;return l(),o("div",null,[i,p(n,{readTime:"2",words:"336"}),y])}const _=e(t,[["render",d]]);export{C as __pageData,_ as default};
