Blob files have to renamed manually to include parent folder path

痞子三分冷 提交于 2020-01-17 03:05:09

问题


We are new to Windows azure and have used Windows azure storage for blob objects while developing sitefinity application but the blob files which are uploaded to this storage via publishing to azure from Visual Studio uploads files with only the file names and do not maintain the prefix folder name and slash. Hence we have to rename all files manually on the windows azure management portal and put the folder name and slash in the beginning of each file name so that the page which is accessing these images can show the images properly otherwise the images are not shown due to incorrect path. Though in sitefinity admin panel , when we upload these images/blob files in those pages , we upload them inside a folder and we have configured to leverage sitefinity to use azure storage instead of database. Please check the file attached to see the screenshot. Please help me to solve this.


回答1:


A few things I would like to mention first:

  1. Windows Azure does not support rename functionality. Rename blob functionality = copy blob followed by delete blob.
  2. Copy blob operation is asynchronous so you must wait for copy operation to finish before deleting the blob.
  3. Blob storage does not support folder hierarchy natively. As you may have already discovered, you create an illusion of a folder by prepending a blob name (say logo.png) with the name of folder you want (say images) and separate them with slash (/) so your blob name becomes images/logo.png.

Now coming to your problem. Needless to say that manually renaming the blobs would be a cumbersome exercise. I would recommend using a storage management tool to do that. One such example would be Azure Management Studio from Cerebrata. If you use that tool, essentially what you can do is create an empty folder in the container and then move the files into that folder. That to me would be the fastest way to achieve your objective.

If you wish to write some code to do that, here are the steps you will take:

  1. First you will list all blobs in a blob container.
  2. Next you will loop over this list.
  3. For each blob (let's call it source blob), you would get its name and prepend the folder name that you want and create an instance of a CloudBlockBlob object.
  4. Next you would initiate a copy blob operation on that blob using StartCopyFromBlob on this new blob where source is your source blob.
  5. You would need to wait for the copy operation to finish. Once the copy operation is finished, you can safely delete the source blob.

P.S. I would have written some code but unfortunately I'm stuck with something else. I might write something later on (but please don't hold your breath for that :)).



来源:https://stackoverflow.com/questions/22038903/blob-files-have-to-renamed-manually-to-include-parent-folder-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!