0
votes

I am trying to upload excel file in azure blob storage with Azure functions (HTTP Trigger ). I attached my code. It is not working properly.

I am getting errors like "Cannot implicitly convert type 'System.Threading.Tasks.Task<System.Collections.Generic.List<FileUpload1.Function1.FileDetails>>' to 'FileUpload1.Function1.FileDetails' FileUpload"

Please help me out from this.

    [FunctionName("Function1")]
    public static FileDetails  Run(
        [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequestMessage req,
        ILogger log)
    {
        if (!req.Content.IsMimeMultipartContent("form-data"))
        {
            throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
        }
        var multipartStreamProvider = new AzureBlobStorageMultipartProvider(BlobHelper.GetWebApiContainer());
        CloudStorageAccount storageAccount = CloudStorageAccount.Parse("configuratorstorage1");
        CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
        CloudBlobContainer container = blobClient.GetContainerReference("excelfiles");
        //var count = container.ListBlobs().Count(); return
        return req.Content.ReadAsMultipartAsync(multipartStreamProvider).ContinueWith(t =>
        {
            if (t.IsFaulted)
            {
                throw t.Exception;
            }
            AzureBlobStorageMultipartProvider provider = t.Result;
            return provider.Files;
        });

I am expecting that I have to upload excel file in azure blob storage with azure functions HTTP trigger.

1
Have you tried to find any examples out there? (there are a ton) social.technet.microsoft.com/wiki/contents/articles/…silent

1 Answers

0
votes

Currently, req.Content.ReadAsMultipartAsync(multipartStreamProvider).ContinueWith(t => ... is returning Task<FileDetails>. You need to await it to get the object you are returning public static FileDetails Run()

return await req.Content.ReadAsMultipartAsync(multipartStreamProvider).ContinueWith(t =>
{
    if (t.IsFaulted)
    {
        throw t.Exception;
    }
    AzureBlobStorageMultipartProvider provider = t.Result;
    return provider.Files;
});

EDIT: After a quick Google - req.Content.ReadAsMultipartAsync(multipartStreamProvider).ContinueWith(t => ... might be returning Task<List<FileDetails>> so try that if the above doesn't work.