PikseladamI'm Lead PLM Systems & Software Engineer. I code stuff & design things. #Arts for art. Working on http://turrsu.com and https://pikseladam.com for fun. #webmentions on pikseladam.
Rails 6 carrierwave production settings for digitalocean spaces with a custom subdomain
Published by Pikseladamon PikseladamI'm Lead PLM Systems & Software Engineer. I code stuff & design things. #Arts for art. Working on http://turrsu.com and https://pikseladam.com for fun. #webmentions on pikseladam.
<p><span
class="gatsby-resp-image-wrapper"
style="position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 620px;"
>
<a
class="gatsby-resp-image-link"
href="/static/33e25b834295192f0dc69c356f60fca6/4b190/rcd.jpg"
style="display: block"
target="_blank"
rel="noopener"
>
<span
class="gatsby-resp-image-background-image"
style="padding-bottom: 74.83870967741935%; position: relative; bottom: 0; left: 0; background-image: url('data:image/jpeg;base64,/9j/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wgARCAAPABQDASIAAhEBAxEB/8QAGQAAAQUAAAAAAAAAAAAAAAAAAAECAwQF/8QAFAEBAAAAAAAAAAAAAAAAAAAAAP/aAAwDAQACEAMQAAAB24LSDgD/xAAYEAADAQEAAAAAAAAAAAAAAAABAhADIf/aAAgBAQABBQJ2ChdRez//xAAVEQEBAAAAAAAAAAAAAAAAAAAQEf/aAAgBAwEBPwGn/8QAFBEBAAAAAAAAAAAAAAAAAAAAEP/aAAgBAgEBPwE//8QAGRABAAIDAAAAAAAAAAAAAAAAAQACICEy/9oACAEBAAY/AugZu5j/AP/EABsQAQACAgMAAAAAAAAAAAAAAAEAEBExIUGR/9oACAEBAAE/IecpaWEcPD2nPUAbRr//2gAMAwEAAgADAAAAEG/P/8QAFhEBAQEAAAAAAAAAAAAAAAAAAREQ/9oACAEDAQE/EKCZ/8QAFhEAAwAAAAAAAAAAAAAAAAAAARAR/9oACAECAQE/EIF//8QAHRABAAICAgMAAAAAAAAAAAAAAQARITFBURBx0f/aAAgBAQABPxB0AqFsv1EFnOMjvqCIJphQWBvkuOYBb0/fH//Z'); background-size: cover; display: block;"
></span>
<img
class="gatsby-resp-image-image"
alt="rcd"
title="rcd"
src="/static/33e25b834295192f0dc69c356f60fca6/935bc/rcd.jpg"
srcset="/static/33e25b834295192f0dc69c356f60fca6/d8321/rcd.jpg 155w,
/static/33e25b834295192f0dc69c356f60fca6/ea106/rcd.jpg 310w,
/static/33e25b834295192f0dc69c356f60fca6/935bc/rcd.jpg 620w,
/static/33e25b834295192f0dc69c356f60fca6/4b190/rcd.jpg 800w"
sizes="(max-width: 620px) 100vw, 620px"
style="width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;"
loading="lazy"
/>
</a>
</span></p>
<p>Hello,</p>
<p>I recently worked on both Active Storage and CarrierWave to store user uploaded files and decided to use CW on my site. (Maybe i will tell why i choose CW over Active Storage in a different article)</p>
<p>I'm using digitalocean spaces since it is basicly cheaper when you don't need a huge storage size.
I also want to use custom subdomain for my stored files so i don't end up messy urls for my file urls. I don't know why but messy urls look dirty to me. Like developer doesn't even care. What a shame....
Coulnd't find a good example for carrierwave settings to use in digitalocean spaces and wanted to share this info myself.
I assume you are installed carrierwave before hand.</p>
<h3>TODO</h3>
<ul>
<li>Create your digitalocean space.</li>
<li>Create a subdomain and attach SSL to it within Digitalocean form. It can be done with couple of clicks.
<span
class="gatsby-resp-image-wrapper"
style="position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 620px;"
>
<a
class="gatsby-resp-image-link"
href="/static/8ff7422f7dd223b95ff6ede188f3ecee/ab75a/CDN.jpg"
style="display: block"
target="_blank"
rel="noopener"
>
<span
class="gatsby-resp-image-background-image"
style="padding-bottom: 16.774193548387096%; position: relative; bottom: 0; left: 0; background-image: url('data:image/jpeg;base64,/9j/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wgARCAADABQDASIAAhEBAxEB/8QAFgABAQEAAAAAAAAAAAAAAAAAAAIF/8QAFAEBAAAAAAAAAAAAAAAAAAAAAP/aAAwDAQACEAMQAAAB3aAD/8QAFBABAAAAAAAAAAAAAAAAAAAAEP/aAAgBAQABBQJ//8QAFBEBAAAAAAAAAAAAAAAAAAAAEP/aAAgBAwEBPwE//8QAFBEBAAAAAAAAAAAAAAAAAAAAEP/aAAgBAgEBPwE//8QAFBABAAAAAAAAAAAAAAAAAAAAEP/aAAgBAQAGPwJ//8QAFRABAQAAAAAAAAAAAAAAAAAAARD/2gAIAQEAAT8hAv8A/9oADAMBAAIAAwAAABCDz//EABQRAQAAAAAAAAAAAAAAAAAAABD/2gAIAQMBAT8QP//EABQRAQAAAAAAAAAAAAAAAAAAABD/2gAIAQIBAT8QP//EABcQAQEBAQAAAAAAAAAAAAAAAAEAEaH/2gAIAQEAAT8QMrnYLC//2Q=='); background-size: cover; display: block;"
></span>
<img
class="gatsby-resp-image-image"
alt="CDN subdomain"
title="CDN subdomain"
src="/static/8ff7422f7dd223b95ff6ede188f3ecee/935bc/CDN.jpg"
srcset="/static/8ff7422f7dd223b95ff6ede188f3ecee/d8321/CDN.jpg 155w,
/static/8ff7422f7dd223b95ff6ede188f3ecee/ea106/CDN.jpg 310w,
/static/8ff7422f7dd223b95ff6ede188f3ecee/935bc/CDN.jpg 620w,
/static/8ff7422f7dd223b95ff6ede188f3ecee/5d472/CDN.jpg 930w,
/static/8ff7422f7dd223b95ff6ede188f3ecee/efc8b/CDN.jpg 1240w,
/static/8ff7422f7dd223b95ff6ede188f3ecee/ab75a/CDN.jpg 1428w"
sizes="(max-width: 620px) 100vw, 620px"
style="width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;"
loading="lazy"
/>
</a>
</span></li>
<li>Go to <strong>API</strong> panel and create a key. Store your key info somewhere safe.</li>
<li>Give folder permissons for your domain.
<span
class="gatsby-resp-image-wrapper"
style="position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 620px;"
>
<a
class="gatsby-resp-image-link"
href="/static/d7ee09a2a272f50180fa9a112f9b142d/90b4c/domain_permias.jpg"
style="display: block"
target="_blank"
rel="noopener"
>
<span
class="gatsby-resp-image-background-image"
style="padding-bottom: 23.87096774193548%; position: relative; bottom: 0; left: 0; background-image: url('data:image/jpeg;base64,/9j/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wgARCAAFABQDASIAAhEBAxEB/8QAFgABAQEAAAAAAAAAAAAAAAAAAAEF/8QAFAEBAAAAAAAAAAAAAAAAAAAAAP/aAAwDAQACEAMQAAAB3qAH/8QAFBABAAAAAAAAAAAAAAAAAAAAEP/aAAgBAQABBQJ//8QAFBEBAAAAAAAAAAAAAAAAAAAAEP/aAAgBAwEBPwE//8QAFBEBAAAAAAAAAAAAAAAAAAAAEP/aAAgBAgEBPwE//8QAFBABAAAAAAAAAAAAAAAAAAAAEP/aAAgBAQAGPwJ//8QAFRABAQAAAAAAAAAAAAAAAAAAARD/2gAIAQEAAT8hC//aAAwDAQACAAMAAAAQg8//xAAUEQEAAAAAAAAAAAAAAAAAAAAQ/9oACAEDAQE/ED//xAAUEQEAAAAAAAAAAAAAAAAAAAAQ/9oACAECAQE/ED//xAAZEAEAAgMAAAAAAAAAAAAAAAABABFBccH/2gAIAQEAAT8QrvkByw3P/9k='); background-size: cover; display: block;"
></span>
<img
class="gatsby-resp-image-image"
alt="permissions"
title="permissions"
src="/static/d7ee09a2a272f50180fa9a112f9b142d/935bc/domain_permias.jpg"
srcset="/static/d7ee09a2a272f50180fa9a112f9b142d/d8321/domain_permias.jpg 155w,
/static/d7ee09a2a272f50180fa9a112f9b142d/ea106/domain_permias.jpg 310w,
/static/d7ee09a2a272f50180fa9a112f9b142d/935bc/domain_permias.jpg 620w,
/static/d7ee09a2a272f50180fa9a112f9b142d/5d472/domain_permias.jpg 930w,
/static/d7ee09a2a272f50180fa9a112f9b142d/efc8b/domain_permias.jpg 1240w,
/static/d7ee09a2a272f50180fa9a112f9b142d/90b4c/domain_permias.jpg 1398w"
sizes="(max-width: 620px) 100vw, 620px"
style="width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;"
loading="lazy"
/>
</a>
</span></li>
<li>Install necessary gems to use carrierwave with digitalocean.</li>
</ul>
<pre><code class="language-ruby">gem "fog-aws" # storage for AWS S3 digitalocean
</code></pre>
<ul>
<li>Go to your uploader.rb file, in my case it is <code>app/uploaders/image_uploader.rb</code>.</li>
</ul>
<pre><code class="language-ruby"># storage :file. Change this to `fog`
storage :fog
</code></pre>
<ul>
<li>This is the <code>config/initializers/carrierwave.rb</code> file. This file configures carrierwave to use digitalocean spaces for your website in production.</li>
</ul>
<pre><code class="language-ruby">CarrierWave.configure do |config|
config.fog_credentials = {
provider: 'AWS', # required
aws_access_key_id: 'your-key-id', # required unless using use_iam_profile
aws_secret_access_key: 'your-secret-key', # required unless using use_iam_profile
region: 'fra1', # optional, default are different from aws.
host: 'fra1.digitaloceanspaces.com', # optional, defaults to nil
endpoint: 'https://fra1.digitaloceanspaces.com'
}
config.fog_directory = 'nameofyourspacesfolder' # required
config.asset_host = "https://sub.domain.com"
config.fog_attributes = { cache_control: "public, max-age=#{365.days.to_i}" } # optional, defaults to {}
end
</code></pre>
<p><code>config.asset_host</code> is doing the custom domain job here. Also be careful about <strong>region</strong> here. It is different from aws defaults.</p>
<p>That should do it. </p>
<p>Best Regards,</p>
<p>Tuna</p>
<p><span
class="gatsby-resp-image-wrapper"
style="position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 620px;"
>
<a
class="gatsby-resp-image-link"
href="/static/33e25b834295192f0dc69c356f60fca6/4b190/rcd.jpg"
style="display: block"
target="_blank"
rel="noopener"
>
<span
class="gatsby-resp-image-background-image"
style="padding-bottom: 74.83870967741935%; position: relative; bottom: 0; left: 0; background-image: url('data:image/jpeg;base64,/9j/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wgARCAAPABQDASIAAhEBAxEB/8QAGQAAAQUAAAAAAAAAAAAAAAAAAAECAwQF/8QAFAEBAAAAAAAAAAAAAAAAAAAAAP/aAAwDAQACEAMQAAAB24LSDgD/xAAYEAADAQEAAAAAAAAAAAAAAAABAhADIf/aAAgBAQABBQJ2ChdRez//xAAVEQEBAAAAAAAAAAAAAAAAAAAQEf/aAAgBAwEBPwGn/8QAFBEBAAAAAAAAAAAAAAAAAAAAEP/aAAgBAgEBPwE//8QAGRABAAIDAAAAAAAAAAAAAAAAAQACICEy/9oACAEBAAY/AugZu5j/AP/EABsQAQACAgMAAAAAAAAAAAAAAAEAEBExIUGR/9oACAEBAAE/IecpaWEcPD2nPUAbRr//2gAMAwEAAgADAAAAEG/P/8QAFhEBAQEAAAAAAAAAAAAAAAAAAREQ/9oACAEDAQE/EKCZ/8QAFhEAAwAAAAAAAAAAAAAAAAAAARAR/9oACAECAQE/EIF//8QAHRABAAICAgMAAAAAAAAAAAAAAQARITFBURBx0f/aAAgBAQABPxB0AqFsv1EFnOMjvqCIJphQWBvkuOYBb0/fH//Z'); background-size: cover; display: block;"
></span>
<img
class="gatsby-resp-image-image"
alt="rcd"
title="rcd"
src="/static/33e25b834295192f0dc69c356f60fca6/935bc/rcd.jpg"
srcset="/static/33e25b834295192f0dc69c356f60fca6/d8321/rcd.jpg 155w,
/static/33e25b834295192f0dc69c356f60fca6/ea106/rcd.jpg 310w,
/static/33e25b834295192f0dc69c356f60fca6/935bc/rcd.jpg 620w,
/static/33e25b834295192f0dc69c356f60fca6/4b190/rcd.jpg 800w"
sizes="(max-width: 620px) 100vw, 620px"
style="width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;"
loading="lazy"
/>
</a>
</span></p>
<p>Hello,</p>
<p>I recently worked on both Active Storage and CarrierWave to store user uploaded files and decided to use CW on my site. (Maybe i will tell why i choose CW over Active Storage in a different article)</p>
<p>I'm using digitalocean spaces since it is basicly cheaper when you don't need a huge storage size.
I also want to use custom subdomain for my stored files so i don't end up messy urls for my file urls. I don't know why but messy urls look dirty to me. Like developer doesn't even care. What a shame....
Coulnd't find a good example for carrierwave settings to use in digitalocean spaces and wanted to share this info myself.
I assume you are installed carrierwave before hand.</p>
<h3>TODO</h3>
<ul>
<li>Create your digitalocean space.</li>
<li>Create a subdomain and attach SSL to it within Digitalocean form. It can be done with couple of clicks.
<span
class="gatsby-resp-image-wrapper"
style="position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 620px;"
>
<a
class="gatsby-resp-image-link"
href="/static/8ff7422f7dd223b95ff6ede188f3ecee/ab75a/CDN.jpg"
style="display: block"
target="_blank"
rel="noopener"
>
<span
class="gatsby-resp-image-background-image"
style="padding-bottom: 16.774193548387096%; position: relative; bottom: 0; left: 0; background-image: url('data:image/jpeg;base64,/9j/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wgARCAADABQDASIAAhEBAxEB/8QAFgABAQEAAAAAAAAAAAAAAAAAAAIF/8QAFAEBAAAAAAAAAAAAAAAAAAAAAP/aAAwDAQACEAMQAAAB3aAD/8QAFBABAAAAAAAAAAAAAAAAAAAAEP/aAAgBAQABBQJ//8QAFBEBAAAAAAAAAAAAAAAAAAAAEP/aAAgBAwEBPwE//8QAFBEBAAAAAAAAAAAAAAAAAAAAEP/aAAgBAgEBPwE//8QAFBABAAAAAAAAAAAAAAAAAAAAEP/aAAgBAQAGPwJ//8QAFRABAQAAAAAAAAAAAAAAAAAAARD/2gAIAQEAAT8hAv8A/9oADAMBAAIAAwAAABCDz//EABQRAQAAAAAAAAAAAAAAAAAAABD/2gAIAQMBAT8QP//EABQRAQAAAAAAAAAAAAAAAAAAABD/2gAIAQIBAT8QP//EABcQAQEBAQAAAAAAAAAAAAAAAAEAEaH/2gAIAQEAAT8QMrnYLC//2Q=='); background-size: cover; display: block;"
></span>
<img
class="gatsby-resp-image-image"
alt="CDN subdomain"
title="CDN subdomain"
src="/static/8ff7422f7dd223b95ff6ede188f3ecee/935bc/CDN.jpg"
srcset="/static/8ff7422f7dd223b95ff6ede188f3ecee/d8321/CDN.jpg 155w,
/static/8ff7422f7dd223b95ff6ede188f3ecee/ea106/CDN.jpg 310w,
/static/8ff7422f7dd223b95ff6ede188f3ecee/935bc/CDN.jpg 620w,
/static/8ff7422f7dd223b95ff6ede188f3ecee/5d472/CDN.jpg 930w,
/static/8ff7422f7dd223b95ff6ede188f3ecee/efc8b/CDN.jpg 1240w,
/static/8ff7422f7dd223b95ff6ede188f3ecee/ab75a/CDN.jpg 1428w"
sizes="(max-width: 620px) 100vw, 620px"
style="width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;"
loading="lazy"
/>
</a>
</span></li>
<li>Go to <strong>API</strong> panel and create a key. Store your key info somewhere safe.</li>
<li>Give folder permissons for your domain.
<span
class="gatsby-resp-image-wrapper"
style="position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 620px;"
>
<a
class="gatsby-resp-image-link"
href="/static/d7ee09a2a272f50180fa9a112f9b142d/90b4c/domain_permias.jpg"
style="display: block"
target="_blank"
rel="noopener"
>
<span
class="gatsby-resp-image-background-image"
style="padding-bottom: 23.87096774193548%; position: relative; bottom: 0; left: 0; background-image: url('data:image/jpeg;base64,/9j/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wgARCAAFABQDASIAAhEBAxEB/8QAFgABAQEAAAAAAAAAAAAAAAAAAAEF/8QAFAEBAAAAAAAAAAAAAAAAAAAAAP/aAAwDAQACEAMQAAAB3qAH/8QAFBABAAAAAAAAAAAAAAAAAAAAEP/aAAgBAQABBQJ//8QAFBEBAAAAAAAAAAAAAAAAAAAAEP/aAAgBAwEBPwE//8QAFBEBAAAAAAAAAAAAAAAAAAAAEP/aAAgBAgEBPwE//8QAFBABAAAAAAAAAAAAAAAAAAAAEP/aAAgBAQAGPwJ//8QAFRABAQAAAAAAAAAAAAAAAAAAARD/2gAIAQEAAT8hC//aAAwDAQACAAMAAAAQg8//xAAUEQEAAAAAAAAAAAAAAAAAAAAQ/9oACAEDAQE/ED//xAAUEQEAAAAAAAAAAAAAAAAAAAAQ/9oACAECAQE/ED//xAAZEAEAAgMAAAAAAAAAAAAAAAABABFBccH/2gAIAQEAAT8QrvkByw3P/9k='); background-size: cover; display: block;"
></span>
<img
class="gatsby-resp-image-image"
alt="permissions"
title="permissions"
src="/static/d7ee09a2a272f50180fa9a112f9b142d/935bc/domain_permias.jpg"
srcset="/static/d7ee09a2a272f50180fa9a112f9b142d/d8321/domain_permias.jpg 155w,
/static/d7ee09a2a272f50180fa9a112f9b142d/ea106/domain_permias.jpg 310w,
/static/d7ee09a2a272f50180fa9a112f9b142d/935bc/domain_permias.jpg 620w,
/static/d7ee09a2a272f50180fa9a112f9b142d/5d472/domain_permias.jpg 930w,
/static/d7ee09a2a272f50180fa9a112f9b142d/efc8b/domain_permias.jpg 1240w,
/static/d7ee09a2a272f50180fa9a112f9b142d/90b4c/domain_permias.jpg 1398w"
sizes="(max-width: 620px) 100vw, 620px"
style="width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;"
loading="lazy"
/>
</a>
</span></li>
<li>Install necessary gems to use carrierwave with digitalocean.</li>
</ul>
<pre><code class="language-ruby">gem "fog-aws" # storage for AWS S3 digitalocean
</code></pre>
<ul>
<li>Go to your uploader.rb file, in my case it is <code>app/uploaders/image_uploader.rb</code>.</li>
</ul>
<pre><code class="language-ruby"># storage :file. Change this to `fog`
storage :fog
</code></pre>
<ul>
<li>This is the <code>config/initializers/carrierwave.rb</code> file. This file configures carrierwave to use digitalocean spaces for your website in production.</li>
</ul>
<pre><code class="language-ruby">CarrierWave.configure do |config|
config.fog_credentials = {
provider: 'AWS', # required
aws_access_key_id: 'your-key-id', # required unless using use_iam_profile
aws_secret_access_key: 'your-secret-key', # required unless using use_iam_profile
region: 'fra1', # optional, default are different from aws.
host: 'fra1.digitaloceanspaces.com', # optional, defaults to nil
endpoint: 'https://fra1.digitaloceanspaces.com'
}
config.fog_directory = 'nameofyourspacesfolder' # required
config.asset_host = "https://sub.domain.com"
config.fog_attributes = { cache_control: "public, max-age=#{365.days.to_i}" } # optional, defaults to {}
end
</code></pre>
<p><code>config.asset_host</code> is doing the custom domain job here. Also be careful about <strong>region</strong> here. It is different from aws defaults.</p>
<p>That should do it. </p>
<p>Best Regards,</p>
<p>Tuna</p>
Rails 6 carrierwave production settings for digitalocean spaces with a custom subdomain
Hello,
I recently worked on both Active Storage and CarrierWave to store user uploaded files and decided to use CW on my site. (Maybe i will tell why i choose CW over Active Storage in a different article)
I'm using digitalocean spaces since it is basicly cheaper when you don't need a huge storage size.
I also want to use custom subdomain for my stored files so i don't end up messy urls for my file urls. I don't know why but messy urls look dirty to me. Like developer doesn't even care. What a shame....
Coulnd't find a good example for carrierwave settings to use in digitalocean spaces and wanted to share this info myself.
I assume you are installed carrierwave before hand.
TODO
Create your digitalocean space.
Create a subdomain and attach SSL to it within Digitalocean form. It can be done with couple of clicks.
Go to API panel and create a key. Store your key info somewhere safe.
Give folder permissons for your domain.
Install necessary gems to use carrierwave with digitalocean.
gem "fog-aws" # storage for AWS S3 digitalocean
Go to your uploader.rb file, in my case it is app/uploaders/image_uploader.rb.
# storage :file. Change this to `fog`
storage :fog
This is the config/initializers/carrierwave.rb file. This file configures carrierwave to use digitalocean spaces for your website in production.
CarrierWave.configure do |config|
config.fog_credentials = {
provider: 'AWS', # required
aws_access_key_id: 'your-key-id', # required unless using use_iam_profile
aws_secret_access_key: 'your-secret-key', # required unless using use_iam_profile
region: 'fra1', # optional, default are different from aws.
host: 'fra1.digitaloceanspaces.com', # optional, defaults to nil
endpoint: 'https://fra1.digitaloceanspaces.com'
}
config.fog_directory = 'nameofyourspacesfolder' # required
config.asset_host = "https://sub.domain.com"
config.fog_attributes = { cache_control: "public, max-age=#{365.days.to_i}" } # optional, defaults to {}
end
config.asset_host is doing the custom domain job here. Also be careful about region here. It is different from aws defaults.