Saving a file in OneDrive from Azure Functions - c#

What's the simplest way for an Azure Functions to save a file into OneDrive? How does authentication work from a deployed Azure Function?
To make this discussion simpler, we have a string var content = "This is the file content" which needs to be saved as sample.txt file.
What if OneDrive folder is shared with an URL (real shared OneDrive link, will be removed - https://1drv.ms/f/s!Ak7ywxppmRtB8uRKhvT1FLmNBwXNwQ) and no authentication is required?

I'd recommend taking a look at the Microsoft Graph APIs for managing files stored in OneDrive.
They have great C# examples using the Microsoft.Graph NuGet package. You will need to implement a mechanism of authentication however and I don't think there is a way around this. For the Graph, I'd recommend looking at these implementations for getting authenticated for a user.
Once you've authenticated in your Function app, you should be able to get to where you need to be using the Graph APIs for OneDrive available.
List a user's drives
Upload or update a file in a drive

Related

Copy .csv file from Azure Blob Storage to Sharepoint site

I have a CSV file stored in blob storage. The goal is to move this file into a Sharepoint site and set some metadata. What would be the best way to do this? The client does not want us to use Power Automate or Logic Apps.
I tried using Azure Data Factory but there seems to be an issue with writing data to SharePoint. I used the copy activity but the 'sink' to SharePoint failed. Does data factory support writing to Sharepoint?
The client does not want us to use Power Automate or Logic Apps.
Why not? This is the simplest way to achieve this, and is also better maintainable than for instance C# code.
Does data factory support writing to Sharepoint?
Yes, it does. However, using Data Factory only to copy a file to SharePoint is quite a bit of overkill.
If Logic Apps are not an option, have a look at an Azure Function to automatically trigger when the file is created in Azure Storage, and have a look at for instance Upload File To SharePoint Office 365 Programmatically Using C# CSOM – PNP for a C# way of uploading a file to SharePoint.

How to upload files to an Azure Batch auto storage via Azure Batch SDK?

It seems the Azure Batch SDK only supports downloading of blobs from the linked storage account via ResourceFile.FromAutoStorageContainer(...). However, I couldn't find an easy way to upload files via the SDK.
Is there an Azure-Batch-SDK-native way to upload files to the link storage account (aka. auto storage)? Or do I really need Microsoft.Azure.Storage & Microsoft.Azure.Storage.Blob as suggested in this example here.
You can use the OutputFiles functionality to accomplish this. See the full guide for more information.

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

How to properly upload video files to Azure Media Services from angularjs

For my scenario, our current app is begin coded in html5 and angularjs communicating with web api. I have a workflow scenario that I seem to not be able to find an end to end example for. I would like to allow users of my website to upload videos and images to Azure Media Services. I found several examples that seem to move the data from a web page to blob storage and then copy over to azure media services.
Is there a way to upload the file directly to Media Services, instead of having a temporary and permanent blob container(one tied to AMS), as this approach seems to force me to have an additional storage container or is there a way to move the file to blob storage followed by linking the blob file to AMS via IAssetFile?
Can someone provide an end example that demonstrates the flow from web frontend upload to the file ending up in AMS?
Once up there, is there a way to make sure users can view but not download videos?
1.Is there a way to upload the file directly to Media Services:
The Media Services SDK requires you to first create an Asset object in our system. That Asset object is backed by a container in Storage. You can create an empty Asset object, and request a write only SAS URL (We call them "Locators" in our API) to upload your content directly into. You may want to check out this AngularJS module and see if it works. http://ngmodules.org/modules/angular-azure-blob-upload
2.Can someone provide an end example that demonstrates the flow from web frontend upload to the file ending up in AMS?
Your web API/frontend should use the Media Services SDK to create the empty Asset first. Once created, hand create a write only SAS URL and hand that back to your Angular client. The Angular client can then use client side javascript library to upload directly to the blob/container using the SAS URL and a module for azure-blob upload like the one here: http://ngmodules.org/modules/angular-azure-blob-upload
3.Once up there, is there a way to make sure users can view but not download videos?
Once the video is uploaded, you should Delete the Write only SAS "Locator" from your Asset's Locators collection. This way, nobody can use it to write again.
At this point you can create a Streaming Locator. Users will only be able to stream the file through our streaming services. Your file has to be encoded in a format that we can support streaming for, so you may have to first kick off an encoding job to get it into the right format and encoding settings (MP4 files with H264 and AAC audio). If you want to stream from Media Services, you need to make sure you have at least 1 streaming reserved unit enabled on your account. In addition, if you are looking to protect your files, you can take a look at our Content Protection services, which will provide on-the-fly AES 128 or PlayReady DRM encryption to your assets. You can integrate that with JWT tokens and Active Directory to authenticate/auth your users before they are able to decrypt the video on the client side.
I'm not too familiar with Azure Media Services but after looking at this guide http://azure.microsoft.com/en-us/documentation/articles/media-services-rest-get-started/ it appears to me that you can create an asset on Azure Media Services and link it to a blob. This means you'll only have one blob container.
AMS provides Rest API for all media processing capabilities including uploading, encoding, publishing. There is a sample project (postman collection) in GitHub to play around. This sample project is also accompanied by a well-written article. Please find the links below.
https://github.com/Azure-Samples/media-services-v3-rest-postman
https://learn.microsoft.com/en-us/azure/media-services/latest/stream-files-tutorial-with-rest
Hope this will help

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