Get FileInfo from remote path - c#

I have some files on Azure Storage eg
http://mywebsite.blob.core.windows.net/scans/1d251700-5457-49c6-abec-c70fa37f77dd.png
I am using MVC app as my api to process files etc.
To do what I want I need to create FileInfo object from the image.
Is it possible somehow using path as above?

You need to utilise the Azure Storage SDK in your application. This can be installed via nuget in Visual Studio. Once you have this installed you need to setup an access key to the blob storage location(s) you are reading and writing from and use the Storage client. There is a great how-to on the Azure documentation site.

Related

Creating a local PDF file in Azure Function Linux consumption plan with Microsoft Playwright

I am using Microsoft Playwright in order to create a PDF from a remote website inside an Azure Function (HTTP trigger). The method used is page.GetPdfAsync() that only handles a file path in order to create the generated PDF file. I would like to store the file in an Azure Blob storage container but as the GetPdfAsync() method doesn't handle stream or Azure blob storage, I am trying to temporary store the generated file. I tried to use different local folders such as /tmp or /local but each time I trigger the function I see an exception in the trace saying that the filesystem is read-only.
I read this blog post from Anthony Chu so it seems that Playwright is now supported on a Linux consumption plan but in the article the generated screenshot is directly sent back in the HTTP response and never not stored on the local disk.
For the coding environment, I am using C#, VS 2019 and Azure Function Core Tools + Azure CLI for the deployment.
Any idea how I can handle this scenario?
Page.GetPdfAsync() returns a byte[]. You can pass null to the path and upload the resulting byte[] to Azure.

How to save image on Linux (Debian) using ASP.NET CORE 3

I will have to accomplish this new task, to save images on Linux (Debian) server using ASP.NET Core 3. Any idea how to do that. What are the best practices? Any advice are welcome.
thnx
If the blob you mentioned is azure blob storage, you can take a look the following solutions as per your need.
1.If you want to use asp.net core save images to azure blob storage -> then from blob storage, save it to linux file system.
You can first install this nuget package Microsoft.Azure.Storage.Blob to your asp.net core, and refer to this link for saving images to azure blob storage via code(Note that this code is for this older package WindowsAzure.Storage, you need to modify a little). When the images are stored in azure blob storage, you can use blobfuse to map blob storage to your linux server.
2.If you just want to directly save images from asp.net core to linux server, then you should setup a ftp server in the linux server, then directly save images to that linux via ftp.
Hope it helps.

Access to Azure File Storage via VNet

I faced with follow problem hope I can find the way for solving with your help.
I created follow Azure resources:
WebApp Service (Asp.Net Core web application)
FileStorage
VirtualNetwork
All resources created in one resources group. I trying to upload file from my WebApp to File storage via VNet (I need to secure storage so it must be unaccessable from outside internet).
Virtual Network have subnet, wich have setup a Microsoft.Storage - Service endpoints. This sub net is included In Storage firewall settings.
For work with Azure storage I use Microsoft.WindowsAzure.Storage package.
When I trying to get access to storage from webapp I get 403 error.
For access I use 'primary file service endpoint' - https://myaccount.file.core.windows.net/
What I have missed ?
Thnx for any advice !
Azure File shares can’t be accessed from Azure App Service web apps. Refer this feedback item where the feature was declined.

Upload a file to Dropbox from Azure webjob

I have been looking all over the place but I'm having a hard time finding out how to upload a file to Dropbox from an Azure webjob. Is this even possible? I will be creating an excel file and a text document in my webjob that i will need to place in a certain Dropbox account (which i have access) folder.
According to your requirement, I assumed that you could follow the possible approaches below to achieve your purpose.
1.Call Dropbox API in your WebJob
You could leverage Dropbox.NET which is a portable Class Library for you to easily integrate Dropbox into your WebJob.
2. ApiHub extension for Azure WebJob
You could leverage Microsoft.Azure.WebJobs.Extensions.ApiHub which is a pre-release version for you to integrate Dropbox with WebJob. For more details, you could refer to Azure WebJobs extensions sample.
Alternatively (if you don't want to deal with DropBox API) you can build a logic app being triggered for example by HTTP request from your web job as DropBox connector exists:
https://learn.microsoft.com/en-us/azure/connectors/connectors-create-api-dropbox

Where do I store media in an Azure Web App with C# ASP.NET

I am creating a C# ASP.NET app (using Visual Studio), which I'm hosting on Microsoft Azure. Currently, I have a folder in the solution named "Content", in which I store some media. For example, there a logo that is placed on the website.
The purpose of the web app is to generate a document that a user can download after entering some data. To generate this document, I also need to use some media (mainly images). There can be quite a lot of such images!
Where should I store these images? I currently have them in this "Content" folder as well (in seperate sub folders for each user), but I noticed on Azure there is also a tab called "Storage". I have tried to use this service for a bit, but I don't really understand its purpose. Would it be advisable to use this for storing the media, and then retrieving them with the web app when necessary, or should I leave them on the web app server? What is considered Good Practice?
Thanks in advance for any help
As a starting point, using Blob storage (see Azure Storage Documentation) would be significantly better than file storage on a single webserver - its cheaper and more scalable (pricing tiers for Application server storage will be expensive, you'd have have to duplicate files or have a multi-server directory in a load-balanced environment). The basic design is the application will use an SDK to retrieve the bits and then stream it back to the web browser or other client.
If you anticipate many users downloading the same file, and network performance matters, consider using a Content Delivery Network
You should store it in an Azure Storage Account and reference it using the SDK, after generating the document, you can use Shared Access Signature to give the user access and you can limit the access to read or write for a specific time.
If you will generate videos then you can serve it through Azure Media Services

Categories