1

I have the following code to retrieve the duration of a video uploaded:

HttpPostedFileBase postedFileCopy = postedFile;
postedFileCopy.InputStream.Position = 0;
Stream stream = postedFile.InputStream;

LocalResource tempDirectory = RoleEnvironment.GetLocalResource("TempZipDirectory");
postedFile.SaveAs(tempDirectory.RootPath + @"\" + postedFile.FileName);

ShellFile so = ShellFile.FromFilePath(tempDirectory.RootPath + @"\" + postedFile.FileName);
string durationString;
double nanoseconds;                
double.TryParse(so.Properties.System.Media.Duration.Value.ToString(),out nanoseconds);

if (nanoseconds > 0)
{
  int totalSeconds = (int)Math.Round((nanoseconds / 10000000), 0);
  int seconds = totalSeconds % 60;
  int minutes = totalSeconds / 60;
  int hour = totalSeconds / (60 * 60);
  durationString = "" + hour + ":" + minutes + ":" + seconds;
}
else
{
  System.Diagnostics.EventLog.WriteEntry("Application", "BLANK DURATION STRING", System.Diagnostics.EventLogEntryType.Error);
  durationString = "00:00:00";
}

This works as expected on localhost but when put up to Azure storage it does not seem to be able to retrieve the details of the file. The

postedFile.SaveAs(tempDirectory.RootPath + @"\" + postedFile.FileName);

saves the upload to the directory so i can grab these details but no matter what i try I cant seem to get the nanoseconds returned when the storage is on azure. This is a deployed MVC application and the tempdirectory is stored on the C:/ drive of the server.

Jay
  • 3,012
  • 14
  • 48
  • 99

1 Answers1

1

The code you refer is using native (Shell) functions. As AzureWebSites is running as a high-density shared environment, your code runs into non-full-trust mode. Calls to native functions is restricted in Azure Web Sites, even if you scale to reserved mode instances.

UPDATE

The only way to get application executed under FULL TRUST is to use Web Role (for web projects) or Worker Role (for background tasks).

Read more about cloud services here.

astaykov
  • 30,768
  • 3
  • 70
  • 86
  • 1
    Is there any workaround that you could think of which would allow me to use this on Azure or should this be ruled out of the question as a solution? I have deployed the WindowsAPICodepack dll and the shell should these not run with the app as full trust? – Jay Sep 17 '13 at 08:09