Created
February 12, 2014 15:39
-
-
Save lars-erik/8957826 to your computer and use it in GitHub Desktop.
Move Umbraco media to Azure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
update cmsPropertyData set | |
dataNvarchar = 'http://myaccountname.blob.core.windows.net' + dataNvarchar | |
where | |
propertyTypeId in (6, 24) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using Microsoft.WindowsAzure.Storage; | |
namespace MediaToAzure | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var accountName = args[0]; | |
var accountKey = args[1]; | |
var containerName = args[2]; | |
var connectionString = String.Format( | |
"DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}", | |
accountName, | |
accountKey | |
); | |
var account = CloudStorageAccount.Parse(connectionString); | |
var client = account.CreateCloudBlobClient(); | |
var container = client.GetContainerReference(containerName); | |
foreach (var folder in Directory.GetDirectories(".")) | |
{ | |
var lastIndexOfSlash = folder.LastIndexOf(@"\"); | |
var folderName = folder.Substring(lastIndexOfSlash + 1); | |
foreach (var file in Directory.GetFiles(folder)) | |
{ | |
var fileName = Path.GetFileName(file); | |
var blobName = String.Format("{0}/{1}", folderName, fileName); | |
var blob = container.GetBlockBlobReference(blobName); | |
Console.WriteLine("Uploading " + blobName); | |
using (var stream = File.OpenRead(file)) | |
{ | |
blob.UploadFromStream(stream); | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment