设置存储在Blob上的媒体文件的内容types

我们有一个在Azure上托pipe的网站。 这是基于媒体,我们正在使用JWPlayer播放与HTTP pseudostreaming媒体。 媒体文件以三种格式存储在blob上 – mp4,ogg,webm。

问题是媒体文件的内容types被设置为所有types的application / octet-stream。 由于这个,在媒体播放和进度条中有一些问题。

如何设置存储在blob(如 – video/ MP4,video/ ogg,video/ WebM)的适当的内容types的文件?

我不想为每个文件手动进行blob接口。 必须有其他的方式来做到这一点,我不知道。 也许configuration文件,设置文件等等。 或者也许是一个代码块来设置存储在文件夹中的所有文件的内容types。

有什么build议么? 谢谢

这应该工作:

var storageAccount = CloudStorageAccount.Parse("YOURCONNECTIONSTRING"); var blobClient = storageAccount.CreateCloudBlobClient(); var blobs = blobClient .GetContainerReference("thecontainer") .ListBlobs(useFlatBlobListing: true) .OfType<CloudBlockBlob>(); foreach (var blob in blobs) { if (Path.GetExtension(blob.Uri.AbsoluteUri) == ".mp4") { blob.Properties.ContentType = "video/mp4"; } // repeat ad nauseam blob.SetProperties(); } 

或者build立一个字典,所以你不必写一堆if语句。

这是使用正确的Content-Type将video上传到Azure Blob存储的工作示例:

 public static String uploadFile( CloudBlobContainer container,String blobname, String fpath) { CloudBlockBlob blob; try { blob = container.getBlockBlobReference(blobname); File source = new File(fpath); if (blobname.endsWith(".mp4")) { System.out.println("Set content-type: video/mp4"); blob.getProperties().setContentType("video/mp4"); } blob.upload(new FileInputStream(source), source.length()); return blob.getUri().toString(); } catch (URISyntaxException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (StorageException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } 

使用php,可以通过如下设置内容types来上传video

 $blobRestProxy = ServicesBuilder::getInstance()->createBlobService($connectionString); //upload $blob_name = "video.mp4"; $content = fopen("video.mp4", "r"); $options = new CreateBlobOptions(); $options->setBlobContentType("video/mp4"); try { //Upload blob $blobRestProxy->createBlockBlob("containername", $blob_name, $content, $options); echo "success"; } catch(ServiceException $e){ $code = $e->getCode(); $error_message = $e->getMessage(); echo $code.": ".$error_message."<br />"; }