Azure File Share Implementation in .Net Core Web API - azure

Can any one suggest how to Upload a file to Azure File Share in.Net Core Web API?
I'm using IFormFile to Upload File.
Note: I'm trying to upload Excel(*.xlsx) File.

Did you had a look at the documentation already?
https://learn.microsoft.com/en-us/azure/storage/files/storage-dotnet-how-to-use-files
https://learn.microsoft.com/en-us/dotnet/api/azure.storage.files.shares.sharefileclient.uploadasync?view=azure-dotnet
It should look similar to this (Note: this code is not functionally, just made it up by memory)
var file = Request.Form.Files[0];
if (file.Length > 0)
{
Stream fileStream = file.OpenReadStream();
shareFileClient.UploadAsync(fileStream);
}

Related

Azure functions sending a file to sftp server

I came across https://github.com/sshnet/SSH.NET library for connecting with sftp server, however It says its only compatible with .net framework while we use .net core for writing azure functions. Does anyone know any other way? Also how do I send the file to the server once I am connected to the server.
Have used Renci.SshNet with Azure Functions successfully.
Upload is as simple as:
var connectionInfo = new ConnectionInfo(
config["SftpHostname"],
username,
new PasswordAuthenticationMethod(username, config["SftpPassword"]
));
sftpClient = new SftpClient(connectionInfo);
sftpClient.Connect();
sftpClient.UploadFile(requestFile, filePath);

I want to download a file from storage

file path
https://ubj10edustgcdn.azureedge.net/userdata/documents/a09b372d-cffe-438a-b98d-123d118ac0a5/provincial management service batch.pdf
how can i downlaod file from this path by c#
var filepath ="https://ubj10edustgcdn.azureedge.net/userdata/documents/a09b372d-cffe-438a-b98d-123d118ac0a5/provincial management service batch.pdf";
return File(filepath, "application/force-download", Path.GetFileName(filepath));
this code return exception that virtual path is not valid.
The URL contains azureedge.net, which means it's served from a CDN. Which also means you will not be downloading from storage, but 'just' a file from the internet.
Have a look at How to download a file from a URL in C#?
using (var client = new WebClient())
{
client.DownloadFile("http://example.com/file/song/a.mpeg", "a.mpeg");
}
If you actually want to download a file from Azure Storage, you will need to know the (internal) path to the file and you can use code like this to download the file:
string connectionString = CloudConfigurationManager.GetSetting("StorageConnection");
BlobContainerClient container = new BlobContainerClient(connectionString, "<CONTAINER-NAME>");
var blockBlob = container.GetBlobClient("<FILE-NAME>");
using (var fileStream = System.IO.File.OpenWrite("<LOCAL-FILE-NAME>"))
{
blockBlob.DownloadTo(fileStream);
}
Source: Uploading and Downloading a Stream into an Azure Storage Blob

How to store files in firebase using node.js

I have a small assignment where I will have a URL to a document or a file like google drive link or dropbox link.
I have to use this link to store that file or doc in firebase using nodejs. How should i start?
Little head's up might help. What should i use? Please help I'm stuck here.
The documentation for using the admin SDK is mostly covered in GCP documentation.
Here's a snippet of code that shows how you could upload a image directly to Cloud Storage if you have a URL for it. Any public link works, whether it's shared from Dropbox or somewhere else on the internet.
Edit 2020-06-01 The option to upload directly from URL was dropped in v2.0 of the SDK (4 September 2018): https://github.com/googleapis/nodejs-storage/releases/tag/v2.0.0
const fileUrl = 'https://www.dropbox.com/some/file/download/link.jpg';
const opts = {
destination: 'path/to/file.jpg',
metadata: {
contentType: 'image/jpeg'
}
};
firebase.storage().bucket().upload(fileUrl, opts);
This example is using the default bucket in your application and the opts object provides file upload options for the API call.
destination is the path that your file will be uploaded to in Google Cloud Storage
metadata should describe the file that you're uploading (see more examples here)
contentType is the file MIME type that you are uploading

What happens to files downloaded in WebJob

I am working with some sensitive files (mostly images) in my WebJob. My WebJob downloads the files from Azure Blob (container 1), does some processing and uploads to Azure Blob (container 2).
Because these files are sensitive in nature, I want to be 100% sure that WebJob deletes them once the Job is completed running.
Can someone tell me what happens to files downloaded in WebJob?
My download code looks like this ...
var stream = new MemoryStream();
using (StorageService storage = CreateStorageClient())
{
var bucketname = "container1";
var objectToDownload = storage.Objects.Get(bucketname, "files/img1.jpg").Execute();
var downloader = new MediaDownloader(storage);
downloader.Download(objectToDownload.MediaLink, stream);
}
Here CreateStorageClient() is my utility method which creates a StorageService object.
Solved using #lopezbertoni comment.
Also found relevant question which also helped - Azure Webjob - accessing local file system

Upload filestream to cloud-files with Node.js

I know that it's possible to upload files to my cloud-files account in Node.js, using the following module: node-cloudfiles.
But is it also possible to upload a filestream directly?
In my case I am dowloading an image from a certain location in Node.js and want to upload this directly to my cloud-files account without saving the image temporary on my server.
Of course it is possible - you can just read the documentation on Rackspace Cloud Files API ( http://docs.rackspacecloud.com/files/api/cf-devguide-latest.pdf ) and implement the necessary parts yourself.
However, I'd suggest to wait until https://github.com/nodejitsu/node-cloudfiles/pull/11 gets integrated into the trunk - then node-cloudfiles library will support uploading files using streams so you won't have to create files before uploading.

Resources