How can Azure MobileServiceClient be used to upload files? - c#

I am developing a mobile client on Xamarin with a server on Azure Mobile Service.
I use Microsoft.WindowsAzure.MobileServices.MobileServiceClient to send application/json messages to the server.
Now I need to upload files too.
How can I use form/multipart with MobileServiceClient?
TIA

Azure Mobile Services only use data in tables, no files at all. Therefore, the MobileServicesClient is only built to exchange with table data.
You might use other Azure services like Blob Storage to put files there.
If you only need to store really small images, you can put them into the database as textdata, but this has many limitations. Chris Risner has a tutorial on his Blog.

Related

Uploading Image from WebAPi [ Azure Mobile APP] to Folder in Azure Web App

I have created an Azure Mobile App & and Azure Web App. What I need to do is upload image from mobile using webapi endpoint of the Azure Mobile APP and Upload it to a folder inside my Azure Web App.
I am able to get the image in my api using HTTpContext so I can save it inside a folder in the webapi itself but it is not what I need. I have no idea how to save it to folder inside my Web App. But API and WebAPP have same resource group.
Please point me in the right direction as to how it can be done.
I am able to get the image in my api using HTTpContext so I can save it inside a folder in the webapi itself but it is not what I need. I have no idea how to save it to folder inside my Web App. But API and WebAPP have same resource group.
As Azure-Web-App-sandbox states about File System Restrictions/Considerations:
Every Azure Web App has a home directory (d:\home) stored/backed by Azure Storage. This network share is where applications store their content. This directory is available for the sandbox with read/write access.
So for a specific Azure Web App, the Azure Web App content is stored on Azure Storage and is shared among multiple instances. But it does not shared between different web apps.
For uploading file(s) from your mobile app to azure web app, you could leverage the VFS API under KUDU REST API as follows:
PUT /api/vfs/{path}
//Puts a file at path.
PUT /api/vfs/{path}/
//Creates a directory at path. The path can be nested, e.g. `folder1/folder2`.
Note: You need to use the basic authentication. Detailed code snippet, you could follow here.
Additionally, as rahicks pointed out that you could directly upload your resources into a central data storage, then they would be accessed in your multiple applications. And you could leverage Azure Storage Client Library for .NET and directly upload images to your blob storage. Also, you could leverage the storage client library in your azure web app for reading/writing your resources. Detailed tutorials, you could follow here. Moreover, you could use Azure Storage Explorer to manage your storage resources.
///... check rest of request
///... define image path #"image/img1"
///... persist entity with image path
path = Server.MapPath(imagePath);
if(!System.IO.File.Exists(path))
file.SaveAs(Server.MapPath(path));
If you need more help here is a step by step. It's a bit old, but should do the trick.
http://www.c-sharpcorner.com/blogs/how-to-upload-image-and-save-image-in-project-folder-in-mvc1
Update:
Since you need to share between servers it would be best to set up a blob storage account for this. Here is a walkthrough on that:
https://www.codeproject.com/articles/490178/how-to-use-azure-blob-storage-with-azure-web-sites

Moving an asp.net web forms site on azure without coding it again to use azure blob storage

I have a asp.net web forms web site that uses many files from server disk, accept uploads, processing files on the server. All the files stored in the web server's disks.
I would like to move my site to azure web sites. But to do that i think we need to update site code to keep files in azure blobs and process from it. Right now we are not able to that. So can i move my web site to azure without using azure blobs? Is there any way i can move all my site and files to azure, keep and publish on azure but not on azure blobs?
Using Virtual Machine is not an option to us right now.
Every Azure App Service/Website comes with persisted storage, which is technically an Azure storage blob mapped to the local file system. However, your code need not be aware of that. The details are described to the File System section here.
If you can configure paths for your server files, this persisted storage should suffice.

Asp.NET MVC and Azure storage

We are currently working on moving our Asp.NET MVC app from a shared hosting provider to Azure. Our users can upload files such as images and documents to our server and we store these files under app-url/content/data which works pretty well.
Question:
Is it safe to keep doing the same thing and uploading files under app-url/content/data ? I've read about the Azure blob storage but we would like minimize the amount of work required to move to Azure (this is definitely something we could do in the coming months)
Azure provides a number of storage options such as Azure SQL, DocumentDB, Azure Blob storage and more, you can use anyone. If your application is just storing the images, Azure Blob storage is the best option.
Is it safe to keep doing the same thing and uploading files under app-url/content/data ?
Definitely, the security is not concerns to Azure Customers. It is Microsoft's concern you can learn about Azure security from here.
we would like minimize the amount of work required to move to Azure.
This depends upon your application's back-end storage and resource management. If you are setting a new Azure VM for running your application, it might take long. If you are about to use Azure Web Apps (Recommended), it will minimize your migration workload as you may be already familiar with.

Embed/REST API for azure analytics

Is there an API available to pull telemetry/insights data for websites from the azure portal, so I can display that data on my 3rd party site? I'm looking for something similar to Google Analytics embed API.
I do not think there is a specific API for Azure Web Apps analytics (the new name, as I found out today). However, you can configure your web site to log to Azure storage - either table storage or blob storage, and then use the regular storage REST APIs (or use the storage client classes from one of the Azure SDKs). You can do this configuration when you enable logging in the Azure portal. The choices for log destination are File (i.e. the local filesystem - these can then be pulled by FTP) or Table or Blob (these can then be accessed by the storage REST API).
It is summarised here:
http://azure.microsoft.com/en-us/documentation/articles/web-sites-enable-diagnostic-log/
Note: In that link they describe how you can stream logs for real time log viewing (using PowerShell or the Azure command line tools). I think this is intended for debugging purposes rather than embedding in an application, but it might help you...
An alternative approach (disclaimer: I never tried this) is to integrate NewRelic into your application and then use their REST API to extract their monitoring information:
https://docs.newrelic.com/docs/apm/apis/requirements/extracting-metric-data

Accessing OneDrive from Azure Mobile Service

I'm developing a mobile app to share some content between users and I'm facing a weird problem.
Currently, what the app does is to allow the users to download some files from the web and store them on their OneDrive account.
The problem is that I need to download the file from the web first, and then upload it to OneDrive, and this means that I'm wasting double bandwidth for each file (OneDrive does not allow to upload a remote file).
The other required feature is to upload a file from OneDrive to my Azure storage, so, basically, I need my Azure service to work with both upload/download from/to OneDrive.
I can't find anything useful online, but I think I got a solution for the OneDrive-to-Azure scenario:
Get the file ID using the LiveSDK on my phone
Build a download link for the given file
Send the link to the Azure Mobile Service
Download the file in the Azure Storage
I've not tried it yet because I still got no access to Azure (I need to register for the trial), but I'm not sure that this may work, and even if it does I still need to figure out how to make the Azure-to-OneDrive stuff.
Do you guys have any clues?
This thing is really driving me insane :\

Categories

Resources