I am trying to copy a blob from one location to another and it seems like this method is obsolete. Everything I've read says I should use "StartCopy". However, when I try this it doesn't copy the blob. I just get a 404 error at the destination.
I don't seem to be able to find any documentation for this. Can anyone advise me on how to do this in the latest version of the API or point me in the direction of some docs.
Uri uploadUri = new Uri(destinationLocator.Path);
string assetContainerName = uploadUri.Segments[1];
CloudBlobContainer assetContainer =
cloudBlobClient.GetContainerReference(assetContainerName);
string fileName = HttpUtility.UrlDecode(Path.GetFileName(model.BlockBlob.Uri.AbsoluteUri));
var sourceCloudBlob = mediaBlobContainer.GetBlockBlobReference(fileName);
sourceCloudBlob.FetchAttributes();
if (sourceCloudBlob.Properties.Length > 0)
{
IAssetFile assetFile = asset.AssetFiles.Create(fileName);
var destinationBlob = assetContainer.GetBlockBlobReference(fileName);
destinationBlob.DeleteIfExists();
destinationBlob.StartCopyFromBlob(sourceCloudBlob);
destinationBlob.FetchAttributes();
if (sourceCloudBlob.Properties.Length != destinationBlob.Properties.Length)
model.UploadStatusMessage += "Failed to copy as Media Asset!";
}
I'm just posting my comment as the answer to make it easier to see.
It wasn't the access level of the container. It wasn't anything to do with StartCopy either. It turned out to be these lines of code.
var mediaBlobContainer = cloudBlobClient.GetContainerReference(cloudBlobClient.BaseUri + "temporarymedia");
mediaBlobContainer.CreateIfNotExists();
Apparently I shouldn't be supplying the cloudBlobClient.BaseUri, just the name temporarymedia.
var mediaBlobContainer = cloudBlobClient.GetContainerReference("temporarymedia");
There was no relevant error message though. Hopefully it'll save another Azure newbie some time in future.
Related
I'm trying to create a DataDisk in Azure with C#. But nothing seems to work. However was able to do it with PowerShell.
I use Azure SDK.
Below is a piece of code that is suppose to create a disk and attach it.
var vm = azure.VirtualMachines.List().Where(x => x.Name.ToLower() == vmName.ToLower()).FirstOrDefault();
var disk = new DataDisk(
vm.StorageProfile.DataDisks.Count + 1,
DiskCreateOptionTypes.Empty,
vmName + "_disk");
disk.DiskSizeGB = 128;
disk.Validate();
vm.StorageProfile.DataDisks.Add(disk);
vm.StorageProfile.Validate();
vm.Update();
I don't have any errors. But nothing is created.
Could someone tell me what I'm doing wrong?
You're missing the Apply() method after vm.Update(). Please use vm.Update().Apply() instead of vm.Update() in your code.
Here is my test code, and works fine:
#your other code.
DataDisk disk = new DataDisk(vm.StorageProfile.DataDisks.Count + 1,
DiskCreateOptionTypes.Empty,
"ivandisk222");
disk.DiskSizeGB = 15;
disk.Validate();
vm.StorageProfile.DataDisks.Add(disk);
vm.StorageProfile.Validate();
vm.Update().Apply();
After the code completes, I can see the data disk is added to the vm:
I've Vimeo PRO and I'm trying to get the download link so the end user can download the video source. However, the lack of documentation makes it really hard to figure that out.
I'm trying VimeoDotNet but I cannot authenticate, I'm doing the following:
var client = new VimeoClientFactory().GetVimeoClient(key, secret)
var downloadLink = client.GetVideo(video_id).download;
However, the call to GetVideo throws an error saying I have to authenticate first, but I don't see how!
I've also tried with another VimeoClient, but it doesn't seem to implement the download link part.
Can anyone help? Or better yet, share a working example. Thanks.
After 2 days I was finally able to do it, I'll share what I did in case someone needs it. First, download this library:
https://github.com/saeedafshari/VimeoDotNet3
Open in Visual Studio and compile it. It's pretty simple so it compiled right away.
Then reference that compiled DLL from your project and do the following:
var VimeoClient3 = Vimeo.VimeoClient.ReAuthorize(_vimeoAccessToken,
_vimeoAppConsumerKey, _vimeoAppClientSecret);
// videoId is the ID of the video as in the public URL (eg, 123874983)
var result = VimeoClient3.Request("/videos/" + videoId, null, "GET");
if (result == null)
{
throw new Exception("Video not found.");
}
if (result["download"] == null)
{
throw new Exception("Download link not available.");
}
foreach (var item in (ArrayList)result["download"])
{
var downloadLinkInfo = item as Dictionary<string, object>;
if (downloadLinkInfo == null) continue;
// For example, get the link for SD quality.
// As of today, Vimeo was returning an HD quality and a 'mobile' one
// that is for streaming.
if (string.Equals((downloadLinkInfo["quality"] as string), "sd", StringComparison.InvariantCultureIgnoreCase))
{
return downloadLinkInfo["link"] as string;
}
}
I hope this isn't too vague. I am writing an app to run at post-commit hook on our SVN server. When I request the repository URI, I sometimes get an answer that doesn't match the path of my commit.
Here's how I get the commit args in general (edited to add more detail):
public Collection<SvnLogEventArgs> GetCommitArgs(string strUri, long lngRevision)
{
try
{
using (SvnClient client = new SvnClient())
{
SvnLogArgs args = new SvnLogArgs();
Collection<SvnLogEventArgs> col;
args.Start = lngRevision;
args.End = lngRevision;
bool bolGotLog = client.GetLog(new Uri(strUri), args, out col);
return col;
}
}
catch
{
return null;
}
}
But here's how I'm getting the repo URI (GetRepository() basically just reformats it to look like a URL):
colCommitArgs = GetCommitArgs(args[0], long.Parse(args[1]));
strRepository = GetRepository(args[0] + "/" + colCommitArgs[0].ChangedPaths[0].RepositoryPath.ToString());
The args[0] is actually referring to the set of args passed from the commit. I found that ChangedPaths is sometimes empty.
For example, if I commit to C:/Repositories/a_repo/somefolder/example.txt, the value I get back from SVN commit args is just C:/Repositories/a_repo/. This may be a problem with our SVN setup (or my lack of understanding thereof). Why are some folders considered repositories and others just considered folders? Is there a way to specify that a folder isn't just a folder? Or is there a different way in SharpSVN to get the committed-to folder? I'm currently concatenating ChangedPaths[0].RepositoryPath at the end of my original URI.
I don't know much about the C# library that you're using but from a generic Subversion standpoint, you generally need to use two different revision numbers for viewing changes. Try using args.Start = lngRevision - 1; and see what happens.
I am building a Windows c# app that needs to upload files to DropBox. Basically I have everything I need for my app(app secret and app key), but I need to have the client tokens saved to my sql DB for future use. According to Dropbox I am unable to save user login info which is good, but finding a good lib is getting tough.I have tried many different DropBox based libraries but run across the following issues:
SharpBox: seems easy enough to use, but need some kind of deserializer to save the client key and client secret anywhere.
OAuth2 Authorizer: Not enough documentation that I can find, in order for me to actually implement this.
DropNet: This is one that looked promising. It's async and looked good, but again I can't find an example of how to perform the auth function and save the variables to a file/DB/Reg/ or anything.
DropBox.API: This is the method that I currently use and it's working. Problem is it's not Async and requires .NET 4.5. I was ok with all the downs but lately found that's it's very touchy about different versions of JSON and other libraries.
I was hoping someone could give me some assistance in getting any of the above OAUTH libs actually working, Just to get the 3 legged auth process working.
UPDATE::
ok so i am going to include some of the code that I am using at the moment, that uses dropbox.api:
// Get Oauth Token
private static OAuthToken GetAccessToken()
{
string consumerKey = "mykey";
string consumerSecret = "myseceret";
var oauth = new OAuth();
var requestToken = oauth.GetRequestToken(new Uri(DropboxRestApi.BaseUri), consumerKey, consumerSecret);
var authorizeUri = oauth.GetAuthorizeUri(new Uri(DropboxRestApi.AuthorizeBaseUri), requestToken);
Process.Start(authorizeUri.AbsoluteUri);
MessageBox.Show("Once Registration is completed Click OK", "Confirmation");
return oauth.GetAccessToken(new Uri(DropboxRestApi.BaseUri), consumerKey, consumerSecret, requestToken);
}
// Complete Oauth function and write to file
private void button5_Click(object sender, EventArgs e)
{
DialogResult result1 = MessageBox.Show("Please register for dropbox before continuing with authentication. The authorization process will take 1 minute to complete. During that time the backup utility window will be unresponsive. Click yes if you are ready to begin the authorization. HAVE YOU REGISTERED FOR DROPBOX YET?", "DO YOU HAVE A DROPBOX ACCOUNT?", MessageBoxButtons.YesNo);
if (result1 == DialogResult.Yes)
{
try
{
u_w.Enabled = false;
var accesstoken = GetAccessToken();
StringBuilder newFile = new StringBuilder();
string temptoken = "";
string tempsecret = "";
string tempprovider = "";
string tempstatus = "";
string[] file = System.IO.File.ReadAllLines(#"C:\cfg\andro_backup.ini");
foreach (string line in file)
{
if (line.Contains("dbkey:"))
{
temptoken = line.Replace("dbkey:", "dbkey:" + accesstoken.Token);
newFile.Append(temptoken + "\r\n");
continue;
}
if (line.Contains("dbsecret:"))
{
tempsecret = line.Replace("dbsecret:", "dbsecret:" + accesstoken.Secret);
newFile.Append(tempsecret + "\r\n");
continue;
}
if (line.Contains("Provider:"))
{
tempprovider = line.Replace("Provider:", "Provider:DropBox");
newFile.Append(tempprovider + "\r\n");
continue;
}
if (line.Contains("Status:"))
{
tempstatus = line.Replace("Status:", "Status:Connected");
newFile.Append(tempstatus + "\r\n");
continue;
}
newFile.Append(line + "\r\n");
}
System.IO.File.WriteAllText(#"C:\cfg\andro_backup.ini", newFile.ToString());
MessageBox.Show("Completed Backup Provider Setup", "Provider Setup Complete");
Configuration.Reload();
The Above works at the moment and I can upload, download files. The issue is it's not Async and I would like to attempt to stay within the .NET 4.0 if possible, this code requires 4.5
Trying to do the same thing with dropnet, I am unable to get it to work at all even using the examples he has given on the page located here https://github.com/dkarzon/DropNet.
I attempted to look at the demos he has on there as well , but they explaing having the user login everytime to perform any functions, where I need the app to be authorized so it can do it's deeds when it needs to. As far as the code I am using for drop net, I literally just copied and pasted what he had there, just to even see if I can get it to connect and still no go.
If you are using DropNet similar to the examples all you need to do is save the return object from the GetAccessToken method. That returns an instance of a UserLogin object which has the Token and secret on it. Or if you are using the async methods for it then the callback parameter.
Checkout the sample here:
https://github.com/dkarzon/DropNet/blob/master/DropNet.Samples/DropNet.Samples.WP7/MainPage.xaml.cs#L69
Post the code you are using for it so I can give you a better explanation for it.
After scouring the web I am completely stuck on an application I am building to push directories up to Amazon S3 using C# (Targeting .NET 4.5). I am getting NullReferenceExceptions on the line of code that pushes the directory files using the UploadDirectory(TransferUtilityUploadDirectoryRequest) method of the TransferManager class. The problem is I cannot find anything that is null! The debugger doesn't show anything null either, so I'm obviously missing something here.
I read up that if you are uploading to buckets that have periods in them, you need to change the protocol to HTTP otherwise a NullReferenceException might be thrown, however I've done this as well and am continuing to receive the error, even when I created another bucket for testing that has no periods in it.
The portion of my code up to & including the line that causes the exception is below. The class called S3Info is just a helper class that I created that just stores some configuration info such as access/secret keys and other info:
public static void uploadDirectories(S3Info info, List<DirectoryInfo> dirs, Logger logger = null)
{
AmazonS3Config alterConfig = new AmazonS3Config();
alterConfig.CommunicationProtocol = Protocol.HTTP;
AmazonS3Client s3Client = new AmazonS3Client(info.getCredentials(), alterConfig);
TransferUtility directoryTransferUtil = new TransferUtility(s3Client);
TransferUtilityUploadDirectoryRequest uploadDirRequest;
PutObjectRequest completeFileUploadRequest;
uint uploadSuccessCount = 0;
if (dirs == null || dirs.Count == 0)
{
logger.log("Nothing to upload.");
return;
}
//upload directory with PDFs
foreach (DirectoryInfo dir in dirs)
{
try
{
//configure upload request
uploadDirRequest = new TransferUtilityUploadDirectoryRequest();
uploadDirRequest.BucketName = info.selectedBucket.BucketName;
uploadDirRequest.Directory = dir.FullName;
uploadDirRequest.KeyPrefix = dir.Name + #"\";
uploadDirRequest.SearchOption = SearchOption.TopDirectoryOnly;
uploadDirRequest.SearchPattern = "*.pdf";
uploadDirRequest.Timeout = 600000; //10 minutes
//upload directory!
directoryTransferUtil.UploadDirectory(uploadDirRequest); //exception thrown here
I'm a bit stuck at this point so I'm open to any suggestions the community can provide. Thanks.
EDIT: Stack Trace-
Object reference not set to an instance of an object. :
at Amazon.S3.Transfer.Internal.UploadDirectoryCommand.Execute()
at Amazon.S3.Transfer.TransferUtility.UploadDirectory(TransferUtilityUploadDirectoryRequest request)
at S3Delivery.AmazonActions.uploadDirectories(S3Info info, List`1 dirs, Logger logger) in c:\Users\jblacker\Documents\Visual Studio 2012\Projects\S3Delivery\S3Delivery\AmazonActions.cs:line 173
Line 173 is the line referred to above.
A patched version of the SDK (version 1.5.30.1) was released earlier today that fixes this issue.
I posted this same question on the AWS Forums. Apparently the API was broken for the method: UploadDirectory() in version 1.5.30 of the .NET SDK.
Amazon has just posted a patch as version 1.5.30.1