I using Azure Shared Access Signature to create Url to redirect download from my Azure, problem is when download is using Original Name of File, I want to change filename when user download to client.
Anyone have solution.
Thanks
p/s: my Container on Azure is Private permission and I using Asp.net MVC 4
Blobs cannot be renamed or aliased. The only thing you can change is the base dns name (which you can map to a custom name).
That said: If you really wanted to present a unique blob for download and not use the current name, you could make a blob copy (a very fast operation within the same data center) to the name you desire, and then offer up a Shared Access Signature to that new blob. After a reasonable amount of time (maybe just beyond expiration of the SAS), you could then delete the extra blob.
Related
I am a total newbie to Azure WebApps and storage, I need some clarification/confirmation. The main thing to take note of, my application (described below) requires a folder hierarchy. Blob is out of the question and file share doesn't allow anonymous access unless I use Shared Access Signature (SAS).
Am I understanding Azure storage correctly, it's either you fit into the Azure storage model or you don't?
Can anyone advise how I can achieve what's required by the CMS application as described below by using Blobs?
The only option I see is to find a way to change the CMS application so that it always has the SAS in the URL to every file it requests from storage in order to serve content on my Web App? If so, is it a problem if I set my SAS to expire sometime in the distant future?
https://<appname>.file.core.windows.net/instance1/site1/file1.jpg?<SAS>
Problem with using Blob
So far my understanding is that Blob storage doesn't allow "sub folders" as it's a container that holds unstructured data, therefore I'm unable to use this based on my application (described below) as it requires folder structure.
The problem with using File Share
File share seemed perfect as it allows for folder hierarchy, naturally that's what I've used.
However, no anonymous access is allowed for files stored in file storage, the access needs to be authorised. One way of authorising the access is to create a SAS on a file/share level with Read permission and then using that SAS URL to access the file.
Cannot access Windows azure file storage document
My application
I've created a Linux Web App running open source CMS application. This application allows creation of multiple websites, for each website's content such as images, docs, multimedia to be stored on a file server. These files are then served to the website via a defined URL.
The CMS application allows for a settings of the location where it should save its files, this would be a folder on the file server. It then creates a new sub folder for every site it hosts in that location.
Example folder hierarchy
/instance1
/site1
/file1
/file2
/site2
/file1
/file2
Am I understanding Azure storage correctly, it's either you fit into
the Azure storage model or you don't?
You can use Azure Storage Model for your CMS Application. You can use either Blob Storage or File Share
Can anyone advise how I can achieve what's required by the CMS
application as described below by using Blobs?
You can use Data Lake Gen 2 storage account if you want to use Azure Blob Storage.
Data Lake Gen 2 storage enables hierarchical namespace so that you can use subfolders in the Blob Storage as per your requirements
Problem with using Blob
Blob Storage allows subfolders if we use Data Lake Gen 2 storage account. You can enable Blob Public Anonymous access
The problem with using File Share
Azure File Share supports but does not allow public anonymous access. You can use Azure Managed Identity (System-Assigned) for your web app to access the Azure File Share.
Then your application would be able to access the Azure File Share without SAS token
The issue of not having real folders in a blob storage shouldn't be any issue for your use case. Just because it doesn't have your traditional folders doesn't mean it can't serve content on e.g. instance1/site1/file1. That's still possible but the instance1/site1/ will just be part of the name of the blob.
Tools like the Azure Portal or Storage Explorer will actually show folders by using the delimiter / and querying data that appears to be inside a folder by using the path as prefix.
I have a simple need, but there are so many azure options, I am not sure where to start.
I have a AppService (website) on azure from which I want to serve static PDFs for download. In other words, there is a training page on the website, and on this page, I want to have url to the PDF to download it.
But I don't want the PDF's to be a part of the AppService files, I want them in storage so they are a separate from the website files.
How should this be done?
What I have found so far is: Azure Blob storage, but it's not clear to me how to use those with a URL. The samples look like they are using code to download instead of a public URL.
I have also looked at Azure CDN, but that seems like more than I am looking for. Just need a simple location to store and download files.
You can make the blob container public so anyone with the link can download the file.
In this case you can just link to the file or return a 302 redirect from your app to the link, which also initiates the download.
Another option is to use SAS tokens.
These temporary tokens are generated using your storage account access key,
and are attached to the URL.
You can then give this final URL in the link to allow the user to download the file.
In this option the container can be kept private, and you control who can access what.
Now the token is only valid until it expires (you decide this time), so a user could give the link to another person and they could also download the document within that time.
The third option is to pipe the files through your app to the user.
Download the file from your back-end and then stream it to the user for download.
This option takes more resources on your back-end as threads and IO are used there for each download.
This option is the most secure as you can control who can download what.
you can upload your PDFs to Azure Blob storage into a special container (e.g. download) and make that container and content public in either of two ways:
public read access for blobs only: Blobs within the container can be read by anonymous request, but container data is not available. Anonymous clients cannot enumerate the blobs within the container.
Full public read access: All container and blob data can be read by anonymous request. Clients can enumerate blobs within the container by anonymous request, but cannot enumerate containers within the storage account.
Then they are accessible by a URL like https://yourStor.blob.core.windows.net/download/train1.pdf
To expand on the accepted answer
Create a Storage Account, such as mystorage
In the storage account, create a container, such as mycontainer
On the container, set the Access Policy to Blob (Anonymous read access for blobs only).
Upload your file, such as myfile.txt to the container.
View the file Properties. It will show the URL to the file which is in this format: https://mystorage.blob.core.windows.net/mycontainer/myfile.txt
Note that the URL is case sensitive.
I am working on a website where I need to dynamically host images. My intention is to host the images with full URL.
I tried CDN but come to know it has a limitation of that image will only be available 15 mins after upload.
Other options is Blob storage, when I read the document it says "Block blobs" are most ideal for image and media content. Therefore, I am trying to use that.
So, I've following questions:
What is the best way to host images on Azure for such requirements?
If I use Blob storage then how can I get the full URL so that I can that URL to load images in my product?
There really isn't a best way to store images. Some people store them in blob storage (as you referenced), some go with database engines... But, since you asked specifically about how to interact with blob storage and URI's:
All blobs are referenced by uri: http(s)://storagename.blob.core.windows.net/containername/blobname
You can set every blob to private or public (whether at blob or container level), and then either return URI's to your user/webpage (if public) or generate a Shared Access Policy or Shared Access Signature to temporariliy grant access to a private blob (I'll leave that as an exercise for you to look up).
It's completely up to you to create containers and blobs as needed. How you find a blob later is also up to you, so you'll need to think about how you store their names or their URIs (e.g. in a database table somewhere). You can always iterate through containers to search for a given blob, but that is time-consuming, vs direct-retrieval (again, assuming you've stored the URI as metadata somewhere in a database).
I've done a ton of searching and looking at examples but cannot find what I think is possible. I want to give read access on a blob-by-blob basis, and NOT open the entire container to be readable. All the examples I found show how to create a full authenticated URL for a blob, which I got working. What I'm finding is that I can take that SAS key and append that to any other blobs in the same container and they will be readable.
Can I create a SAS key that is only valid for a single BLOB? If so, an example/link would be appreciated!
You can certainly set shared access signature at Blob level. If you're using .Net Storage Client library, do take a look at GetSharedAccessSignature function on a blob. I wrote a blog post on Shared Access Signature some time back where you will find some code for creating SAS for blob: http://gauravmantri.com/2013/02/13/revisiting-windows-azure-shared-access-signature/.
What I need is to rewrite URL for the requested blob, i.e. instead of
http://myaccount.blob.core.windows.net/clients/{client-name}/images/imagefile.jpg
should be served
http://myaccount.blob.core.windows.net/clients/images/imagefile.jpg
The client name in the URL is a request to have SEO URL, as file names are unique and I'd like to have blob name as
images/imagefile.jpg instead of
{client-name}/images/imagefile.jpg and use something like URL rewrite in IIS.
It becomes a pain if the client changes it's name as I can't rename a blob I have to create copy and delete the old blob. It may take more than a minute which we can't afford.
You can't use anything like URL Rewrite for the storage accounts. You can only have custom domain mapped to your storage account. For example instead of referencing blobs with: http://myaccount.blob.core.windows.net/... you could map them to http://img.yourdomain.com/... And you could also use the Azure CDN for better performance and user experience!
Moreover, if you do care about SEO, you have to also think on not just "rename" the blob but also use HTTP 301 redirect from the old blob to the new one. Which also is impossible with Azure storage service. I suggest that you use client-id instead of client-name
UPDATE
You "can" reanme the blobs, simialry to the way you would rename files. Given your requirement - if you want to "quickly" rename a lot of images, you have to write simple "service" anyway, because I can't figure out another way to rename 1000s of files on the file system either. With the blobs, although beeing remote it will be almost the same. And you are wrong that you have to save the blob on the machine. There is new feature (method on the CloudBlob instance) since November'2011 release (I think), named CopyFromBlob. Here is an example of how to rename blobs.. This way you can easily move blobs even around different account without the need to first download the content. Yes, it may take a bit longer than with a local file system. But still this is a fair-enough solution.
Think about what the Azure Storage is. A massively scalable, reliable storage as a service. You have 100TB (subject to increase if required), with 3 copies locally + one copy in another geo region. A CDN support for this massive storage with more than 24 nodes worldwide. I don't think renaming is something of top need.