问题
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:
- Windows Azure does not support rename functionality. Rename blob functionality = copy blob followed by delete blob.
- Copy blob operation is asynchronous so you must wait for copy operation to finish before deleting the blob.
- 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:
- First you will list all blobs in a blob container.
- Next you will loop over this list.
- 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. - Next you would initiate a copy blob operation on that blob using StartCopyFromBlob on this new blob where source is your source blob.
- 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