Using RTM version, Framework 4 due to Azure requirements The code works with an error on the Azure emulator - I suspect that the problem is related to the path / environment variable. Failed to start Azure web role with 404 error
Here is the controller code:
[ValidateInput(false)] public HttpResponseMessage Post() { try { if (!Request.Content.IsMimeMultipartContent("form-data")) { throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType); } string tempPath = RoleEnvironment.GetLocalResource("tempStorage").RootPath; Environment.SetEnvironmentVariable("TEMP", tempPath); Environment.SetEnvironmentVariable("TMP", tempPath); string Host = "test"; string StorageConnection = "credentials here"; string Product = "Product"; string CompanyID = "Company"; DocStorage docStorage = new DocStorage(Host, Product, CompanyID, StorageConnection); var multipartStreamProvider = new AzureBlobStorageMultipartProvider(docStorage.BlobContainer, tempPath); Stream reqStream = Request.Content.ReadAsStreamAsync().Result; if (reqStream.CanSeek) { reqStream.Position = 0; } Request.Content.ReadAsMultipartAsync<AzureBlobStorageMultipartProvider>(multipartStreamProvider).ContinueWith<List<FileDetails>>(t => { if (t.IsFaulted) { throw t.Exception; } AzureBlobStorageMultipartProvider provider = t.Result; foreach (var fileData in provider.FileData) { string fileName = Path.GetFileName(fileData.Headers.ContentDisposition.FileName.Trim('"')); string fileNameBlob = Path.GetFileName(fileData.LocalFileName.Trim('"')); CloudBlob blob = docStorage.BlobContainer.GetBlobReference(fileNameBlob); if (!string.IsNullOrEmpty(provider.FormData["company"])) blob.Metadata[AriettDocStorage.FileNameFileLocation] = provider.FormData["company"]; blob.SetMetadata(); } return provider.Files; }); return new HttpResponseMessage(HttpStatusCode.OK); } catch { return new HttpResponseMessage(HttpStatusCode.NotFound); } }
Here is an override
public class AzureBlobStorageMultipartProvider : MultipartFormDataStreamProvider { public CloudBlobContainer Container; public AzureBlobStorageMultipartProvider(CloudBlobContainer container, string tempPath) : base(tempPath) { Container = container; } public override Task ExecutePostProcessingAsync() {
Glenn source share