Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Baha Al Fataftah 4 posts 75 karma points
    Sep 15, 2018 @ 20:57
    Baha Al Fataftah
    0

    Issue Uploading files to Azure storage blob size 0, from MVC pages surface controller

    HI Guys,

    I need some help/guidance here, I'm trying to upload files into Umbraco but not into the media folder but to the Azure storage Blub.

    The issue: Files uploaded to Blob successfully but corrupted.

    Note: Same files, blob storage, same upload function works in external project out side umbraco works fine !.!

    private async Task<int> SaveCustomDetails(UserMember user, UserCustomViewModel model)
    {
        ..
    
        if (model.ProfessionalImage != null)
        {
            details.ProfessionalImage = await FilesManager.UploadAsync(model.ProfessionalImage, memberId);
        }
    }
    
    public static async Task<string> UploadAsync(HttpPostedFileBase fileToUpload, int memberId)
    {
        string fileFullPath = null;
        if (fileToUpload == null || fileToUpload.ContentLength == 0)
        {
            return null;
        }
        try
        {
            CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["StorageAccountConnection"].ToString());
            CloudBlobClient cloudBlobClient = cloudStorageAccount.CreateCloudBlobClient();
            CloudBlobContainer cloudBlobContainer = cloudBlobClient.GetContainerReference(memberId.ToString());
    
            await cloudBlobContainer.CreateIfNotExistsAsync();
            await cloudBlobContainer.SetPermissionsAsync(
                new BlobContainerPermissions
                {
                    PublicAccess = BlobContainerPublicAccessType.Blob
                }
                );
            string fileName = fileToUpload.FileName;
            CloudBlockBlob cloudBlockBlob = cloudBlobContainer.GetBlockBlobReference(fileName);
            cloudBlockBlob.Properties.ContentType = fileToUpload.ContentType;
            await cloudBlockBlob.UploadFromStreamAsync(fileToUpload.InputStream);
    
            fileFullPath = cloudBlockBlob.Uri.ToString();
        }
        catch (Exception ex)
        {
    
        }
        return fileFullPath;
    }
    

    example of uploaded file

Please Sign in or register to post replies

Write your reply to:

Draft