How to write in an Azure Website from a Webjob? - azure

I know how to write into the storage, but how can I write in a web site from a web job? I want to use a webjob to insert some stuff in an azure database and images in a web site. I know that my webjob is:
uploaded in the dir /App_Data/jobs/triggered/myjob
but I can't write the a dir /images

The your webjob has access to an environment variable called %HOME% using it like this %HOME%\site\wwwroot points you to the root of your site( dir / in your terminology). doing this
var imageDir = Environment.ExpandEnvironmentVariables(#"%HOME%\site\wwwroot\images");
will give you the full path to your images folder in imageDir. Your webjob can write anything there.

Unfortunately, the Azure WebJobs SDK does not support binding to databases or the file system. Only Azure Storage is supported out of the box.
However, you can manually create a connection to a database from a WebJob and perform DB operations.

Related

Is there a way to know if a file has been uploaded to a network drive in Azure

I have a network location where every hour a csv file gets dumped. I need to copy that file to an azure blob. How do I know that a file has been uploaded to that network drive. Is there something like a file watcher in azure which monitors this network location? Also, is it possible to copy a file from network location to an azure blob through code?
I'm using .net core APIs deployed to an Azure App Service.
Please suggest a possible solution.
You can use Azure Event Grid but as of today Event Grid does not support Azure File Share.
As your fileshare in on-prem the only way I see is that you can write a custom publisher which can run on-prem and uses Azure Event Grid to send the event to Azure Event Grid and a subscriber which can be Azure Function does the work you want it to do.
https://learn.microsoft.com/en-us/azure/event-grid/custom-event-quickstart-portal
But it will only be an Event and not the file itself which has been added\changed and to do that you will have to then upload the file itself into Azure for processing as well. As the above way requires you to do two things I would recommend run a custom code on-prem which runs CRON job like and looks for the new or edited file and then uploads to Azure BLOB Storage and then execute Azure Function to do your processing task.
Since the files are on-prem you can use powershell to monitor a folder for new files. Then fire an event to upload the file to an Azure blob.
There is a video showing how to do this here: https://www.youtube.com/watch?v=Usih7UywZYA
The changes you need to make are:
replace the action with an upload to azure https://argonsys.com/microsoft-cloud/library/how-to-upload-files-to-azure-blob-storage-using-powershell-and-azcopy/
Run powershell in the context of a user that can upload files

Read a text file of webapp from webjobs in azure

I have a webapp and in webapp i have some text files uploaded in temp directory. Next, i also have a webjob to process these files but the problem is i'm not able to access these files from that webapp's temp directory.
Is there any way to achieve this?
Thanks in advance.
The standard way of achieving this would be to put the text files in a blob storage and then read it via webjob. Because in Azure you cannot really guarantee that the temp folder would be shared between the web app and the webjob.
The main site and WebJobs don't share the same %TMP% dir, which is why this doesn't work. One option would be to create those files somewhere under d:\home, e.g. in d:\home\data\tmp`. Then you'll be able to access it from both.
Keep in mind that if you scale out, all the instances will be sharing the same folder, so you may need to name the folder after the instance ID if you don't want that.
I would complement Tiklu's answer. You can solve your problem easily with Azure Functions, which is the evolution of Azure WebJobs SDK. You just upload the text file to a blob and use Azure Functions with BlobStorageTrigger to read the content of the file.
here's a sample:
https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-blob

Moving files from Azure Blob / Files storage to Azure FTP space

Would like to know whether it is a feasible to move the folder ( with files ) from Azure blob/file storage to webapp root.
Scenario: Would like to replace gallery of images folder used by static HTML site for gallery section weekly using powershell.
Request suggestions or alternatives as not sure how to handle this in azure and schedule swapping of folders between blob and ftp.
You can use the BlobTrigger trigger with WebJob deployed on the same web app and copy the files from blob storage to the local file system.
Would like to replace gallery of images folder used by static HTML site for gallery section weekly using powershell.
Please try to store the images in Azure blob directly. We can access the images in Azure blob with 'Full public read access' mode or 'Public read access for blobs only' mode. Refer to this article for more details. Then we can use Scheduler Webjob to replace the images directly.
It wasn't clear to me exactly what you are trying to do. If you have a legacy app / adoption of FTP you can mount an FTP server on Azure File Storage. Or alternatively Blob Storage can be used for public data as described above. If you want a simple tool for interacting with Blob Storage then you can try Storage Explorer.

Azure Cloud Web Service, storage options

We are migrating our PHP website to Azure Cloud Web Service (Web Role).
Currently the website saves user submitted image files to the filesystem via drive letter access. These images are then served via a url e.g. content.example.com.
What options have I got id I want persistent file storage on an Azure Cloud Web Service.
I am currently assessing BLOB Storage for this.
Thanks
Blob storage is the right answer. Although you could convert your images in base64 and save them in Azure Sql as well, it is really not recommended.
Check: Azure, best way to store and deploy static content (e.g. images/css)? or Where to store things like user pictures using Azure? Blob Storage?
One of the options to reduce re-writing of your application is to mount blob-storage as a network drive. Here is some information how to do it: http://blogs.msdn.com/b/windowsazurestorage/archive/2014/05/12/introducing-microsoft-azure-file-service.aspx
Mounting of the drives can be done on Web-Role start-up task and can be scripted.

Azure Blob - Multiple files into one zip file before downloading

I'm currenlty using Azure Blob to store files, and upload/download from ASP.Net Application hosted outside of Azure. (I do not have Web Role and Worker Role.)
Is it possible to zip multiple files into one zip file within Azure Blob before downloading?
Thanks in advance!
THe only way to achieve this would be to do it by using a WIndows Azure Compute Role in the cloud. You obviously wouldn't want to do it on your on-prem servers as you'd round-trip the files twice.
One approach you might consider would be to build a download 'client' in Silverlight. This could handle the communications to blob stgorage and pull down the blobs (maybe in parallel) and then create the zip client side for saving.
But the short answer is this is not possible using WIndows Azure storage alone.

Resources