public string PutImage(IWebCamImage webCamImage, out string key) { if (webCamImage.Data != null) // accept the file { // Azure credentials. const string connectionString = "DefaultEndpointsProtocol=https;" + "AccountName=mybigbro;" + "AccountKey={sensitive};"; // Setup the filename. string fileName = Guid.NewGuid() + ".jpg"; string url = null; // Setup the Azure stuff. CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString); CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); var config = ConfigurationManager.AppSettings; CloudBlobContainer container = blobClient.GetContainerReference(config["azureContainer"]); CloudBlockBlob blockBlob = container.GetBlockBlobReference(fileName); // Create or overwrite the "myblob" blob with contents from a local file. using (var memStream = new MemoryStream(webCamImage.Data)) { blockBlob.UploadFromStream(memStream); url = config["azureRootUrl"] + "/" + config["azureContainer"] + "/" + fileName; } // Return our result. key = fileName; return url; } key = null; return null; }
public string PutImage(IWebCamImage webCamImage, out string key) { if (webCamImage.Data != null) // accept the file { // AWS credentials. const string accessKey = "{sensitive}"; const string secretKey = "{sensitive}"; // Setup the filename. string fileName = Guid.NewGuid() + ".jpg"; string url = null; // Drop the image. AmazonS3 client; using (client = Amazon.AWSClientFactory.CreateAmazonS3Client(accessKey, secretKey)) { var request = new PutObjectRequest(); var config = ConfigurationManager.AppSettings; request.WithBucketName(config["awsBucket"]) .WithCannedACL(S3CannedACL.PublicRead) .WithKey(fileName).WithInputStream(new MemoryStream(webCamImage.Data)); S3Response response = client.PutObject(request); url = config["awsRootUrl"] + "/" + config["awsBucket"] + "/" + fileName; } // Return our result. key = fileName; return url; } key = null; return null; }