Tuesday, April 4, 2017

Migrating from dropbox public folder

Dropbox recently removed its public folder feature, which was used to host my blog's images. I have to figure out a solution to host and fix the paths to these images…

Dropbox announced that As of March 15, 2017 the Public folder in your Dropbox account has been converted into a standard folder. Sad, all my previous links are hosted on Dropbox, and they all become invalid URLs.

I figured that I have to use another image hosting service. After some searching online, Cloundinary seems to be a good option. One design of my hosted images are that they are organized in sub-folders under a 'blog' folder. This means that if I want to seamlessly convert the links, I need to preserve the folder structure too.

Cloudinary seems to suggest they support auto-creating folders. Unfortunately that does not quite work for me.

settings
settings

In fact, I wrote a small script to do this.

Upload a folder to cloudinary
1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20  
import os  import cloudinary  import cloudinary.uploader  import cloudinary.api    # Upload the folder in rootdir to cloudinary, preserving the file structure    cloudinary.config(    cloud_name = "<name>",    api_key = "<your key>",    api_secret = "<your secret>"  )    rootdir = 'blog'  for root, subs, files in os.walk(rootdir):      for file in files:          cloudinary.uploader.upload(              os.path.join(root, file),              folder=root, use_filename=True,              unique_filename=False, resource_type='auto')  

With that, I did a simple sed run on all my post sources:

Upload a folder to cloudinary
1  
sed -i '' 's/<dropbox base url>/<cloundinary base url>/' *.markdown  

then rake preview. Boom! All the images are shown again!



via

No comments: