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
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.
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.
When you use a custom handler it just extends the existing, so the default functionality still should be working.
Regards,
Hristo Valyavicharski
Telerik
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