This is a migrated thread and some comments may be shown as answers.

CloudUpload / content type w/azure storage

4 Answers 68 Views
CloudUpload
This is a migrated thread and some comments may be shown as answers.
Travis
Top achievements
Rank 1
Travis asked on 19 Feb 2015, 10:12 PM
Unless I'm trying things out incorrectly, it doesn't seem CloudUpload sets the content type upon successfully uploading a file to azure storage.

I looked into the custom azure provider item, but doesn't seem to be an option to set content type.  

Did I test this out wrong?  Is this a known bug?  Is there a workaround?

4 Answers, 1 is accepted

Sort by
0
Hristo Valyavicharski
Telerik team
answered on 24 Feb 2015, 04:32 PM
Hi Travis,

At the moment CloudUpload set "application/octet-stream", which is a binary file. If you want to set different Content Type you will have to create Custom Azure Provider and override the default upload method:
        public virtual void UploadFileOnSigleRequest(string keyName, NameValueCollection metaData, Stream fileStream)
        {
#if ASPNET35
            var blob = _container.GetBlobReference(keyName);
#else
            var blob = _container.GetBlockBlobReference(keyName);
#endif
            blob.Properties.ContentType = “application/x-shockwave-flash”;
  
            try
            {
                blob.UploadFromStream(fileStream);
  
                for (int i = 0; i < metaData.AllKeys.Length; i++)
                {
                    var key = metaData.GetKey(i);
                    blob.Metadata.Add(key, metaData[key]);
                }
                blob.SetMetadata();
            }
            catch (Exception e)
            {
                var message = string.Format("Exception thrown for upload operation for file with keyName: {0}", keyName);
                throw new CloudUploadProviderException(message, e, keyName, BlobContainer);
            }
        }


Regards,
Hristo Valyavicharski
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Phanindra
Top achievements
Rank 1
answered on 21 Mar 2016, 04:45 AM

HI Hristo Valyavicharski, 

I followed your procedure, it is working as I expected, the problem is  According to the documentation setting UncommitedFilesExpirationPeriod affects "The time after the files are
Deleted from the storage if they are not processed. I gave UncommitedFilesExpirationPeriod  as  2 hours, after 2 hours files were deleted in a container. How we make file is processed at  Custom Azure Provider.

 

Thanks & Regards ,

Phani B.

0
Hristo Valyavicharski
Telerik team
answered on 23 Mar 2016, 02:15 PM
Hi Phani,

When you use a custom handler it just extends the existing, so the default functionality still should be working.

Regards,
Hristo Valyavicharski
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
0
Pat
Top achievements
Rank 1
answered on 25 Jan 2018, 07:23 AM

Hi, I am currently experiencing the same issue. We need to serve the file from the azure blob as jpg, jpeg, png, gif not as binary due to image manipulation module that we use in the query string.

Therefore it is important to set the correct ContentType, but unfortunately I end up having always "application/octet-stream". Do I still need to create a custom azure provider 3 years later? If yes, how can I defer the content type from the Stream object? FileStream would work with something like string extension = Path.GetExtension(myFileStream.Name); but not Stream.?! Could you guide me how to set the correct ContentType e.g. image/jpeg if it is a jpg, rather than application/octet-stream, and equally for other extensions png, gif?!

Couldn't you build in a switch that can turn automatic recognition of the ContentType - For Example Microsofts Azure Storage Explorer sets the ContentType automatically for a file upload. But I am happy to code it myself if you can point me in the right direction how to defer the ContentType from the stream....

Many Thanks in advance

Cheers

Pat

Tags
CloudUpload
Asked by
Travis
Top achievements
Rank 1
Answers by
Hristo Valyavicharski
Telerik team
Phanindra
Top achievements
Rank 1
Pat
Top achievements
Rank 1
Share this question
or