
- Web api file upload example how to#
- Web api file upload example install#
- Web api file upload example update#
- Web api file upload example code#
Previously you could force the files to be saved in the draft area by specifying the then optional parameter: filearea=draft. If the upload is successfully, the files will be saved, prior to at least Moodle 2.9 in the user private file area but since in the user draft area. The entry point is /webservice/upload.php, simply use HTTP POST method to upload files, it requires a web service token for authentication. So we developed some alternative solutions to upload/download files. Mobile devices don't have enough memory to decode/encode web service request/response containing large files.


Web api file upload example how to#
I would suggest to have a look at this articleĬreate and use shared access signatures on how to access your blobs using SAS and Stored Access Policy.Since Moodle 2.0, we provide web service functions to upload and download files.
Web api file upload example update#
Consider the fact that, in case your access keys are compromised, you need to update all your mobile clients to continue accessing your storage account, while in the other case you simply update the credentials to your app and none of your clients is affected. Storage account credentials (account name and key) should not be available to your mobile app to access storage account directly, but only through your Web API app. If you have private blobs that you want to be accessible only, for example, by certain users, I would suggest you to provide a REST API call, in your web api controller, that will generate the Shared Access Signature to access this blob for limited time, or to apply a certain security policy. Shared access signature (SAS) provides a powerful way to grant limited access to objects in your storage account to other clients, without having to expose your account key.
Web api file upload example code#
You can download the source code from here. You can create a simple Post Request through Postman, to test how the above works.Īll successfully uploaded images will be available in “images” container, in Azure Preview Portal. Private readonly string _supportedMimeTypes = has successfully uploaded") Private readonly CloudBlobContainer _blobContainer Public class AzureStorageMultipartFormDataStreamProvider : MultipartFormDataStreamProvider Subsequently, add your storage account credentials in the AppSettings section of your Web.config:Īfterwards, you need to extend MultipartFormDataStreamProvider class by creating your own AzureStorageMultipartFormDataStreamProvider, which will be responsible for writing streamed data directly to a blob in your container. Install-Package WindowsAzure.Storage Add Azure Storage Credentials Or type the command below from Package Manager Console: Then, search for “azure storage” in Nuget Gallery
Web api file upload example install#
Install Windows Azure Storage Nuget package

In order to have access to the container and upload your files, you are going to need: There is no limitation as to the number of containers per account nor as to the number of blobs per container. Let’s name the container in our example “images” and set its access type to Public.

In this tutorial, we will describe the process of creating a Web API project and uploading a file directly to a container in your Azure Storage account. It typically comprises images, audio, or any other file. A blob is a collection of binary data stored as a single entity. Azure Blob Storage is part of the Microsoft Azure Storage service, providing a relatively low cost service for storing large amounts of unstructured data, such as text or blobs “blobs” stands for Binary Large Objects.
