简体   繁体   中英

Which .NET object can I use to move(stream?) a file from a WPF desktop app to an Azure webapp (.NET Core 2)?

I have a WPF desktop app that can use the HTTPClient to move structured data from the desktop to an Azure webapp (and then on to an Azure SQL Server). Now I need to move a file (image or other) from the desktop to the same Azure webapp and then to an Azure Blob. I'm not sure if the HTTPClient is the correct object to move(?stream) the file up to the webapp or if there is a more appropriate object to use. (I will also need to downlown files from the webapp to the WPF desktop app as well).

HttpClient just establishes the channel (and authentication) for back and forth communications with some API; whether the data being transferred is structured or unstructured is practically irrelevant. What should concern you are:

  • are your complex types (or reference types eg classes) correctly defined for the data (eg byte arrays for image/other data) being transferred and processed? Are they also properly nested where applicable?

  • is your serialization mechanism (eg Json.NET versus ProtoBuf-Net) efficient given the data and resources you're working with? Are they also properly configured?

You could use httpclient and build your own web api service you host.

Maybe you want to re-use that end point for some other app like a web site.

Otherwise, you can upload your file straight to azure. No serialisation and deserialisation overhead.

The thing designed for his scenario is CloudBlobClient.

There's a BufferManager which you would usually configure as a WCF Buffer Manager adapter.

It's a bit fiddly but there's example code on github:

https://github.com/Azure-Samples/storage-blob-dotnet-getting-started

https://github.com/Azure-Samples/storage-blob-dotnet-getting-started/blob/master/BlobStorage/Advanced.cs

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM