将图像从WebAPi [Azure Mobile APP]上载到Azure Web App中的文件夹

时间:2017-12-23 20:10:09

标签: c# asp.net-web-api2 azure-web-sites azure-app-service-envrmnt

我创建了一个Azure移动应用程序&和Azure Web App。我需要做的是使用Azure Mobile APP的webapi端点从移动设备上传图像,并将其上传到Azure Web App内的文件夹。

我可以使用HTTpContext在我的api中获取图像,因此我可以将其保存在webapi本身的文件夹中,但这不是我需要的。我不知道如何将其保存到我的Web App中的文件夹中。但API和WebAPP具有相同的资源组。

请指出我如何做到正确的方向。

2 个答案:

答案 0 :(得分:1)

  

我可以使用HTTpContext在我的api中获取图像,因此我可以将其保存在webapi本身的文件夹中,但这不是我需要的。我不知道如何将其保存到我的Web App中的文件夹中。但API和WebAPP具有相同的资源组。

正如Azure-Web-App-sandbox所述有关文件系统限制/注意事项:

  

每个Azure Web App都有一个由Azure Storage存储/支持的主目录(d:\home。此网络共享是应用程序存储其内容的位置。此目录可用于具有读/写访问权限的沙箱。

因此,对于特定的Azure Web App,Azure Web App内容存储在Azure存储中,并在多个实例之间共享。但它不会在不同的网络应用程序之间共享。

要将文件从您的移动应用上传到azure网络应用,您可以使用KUDU REST API下的 VFS API ,如下所示:

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`.

注意:您需要使用基本身份验证。详细的代码段,您可以关注here

此外,由于rahicks指出您可以直接将资源上传到中央数据存储中,因此可以在多个应用程序中访问它们。您可以利用Azure Storage Client Library for .NET并直接将图像上传到blob存储。此外,您可以利用azure Web应用程序中的存储客户端库来读取/写入资源。详细教程,您可以关注here。此外,您可以使用Azure Storage Explorer来管理存储资源。

答案 1 :(得分:0)

 data1=structure(list(d = c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L), 
                 Girth = c(8.3, 8.6, 8.8, 10.5, 10.7, 10.8, 11, 11, 11.1, 
                           11.2), Height = c(70, 65, 63, 72, 81, 83, 66, 75, 80, 75), 
                 Volume = c(10.3, 10.3, 10.2, 16.4, 18.8, 19.7, 15.6, 18.2, 
                            22.6, 19.9)), .Names = c("d", "Girth", "Height", "Volume"
                            ), row.names = c(NA, 10L), class = "data.frame")
 data2=structure(list(X1.2 = 1:2, fun = c("sum", "max")), .Names = c("X1.2", 
                                                                "fun"), row.names = c(NA, -2L), class = "data.frame")

如果您需要更多帮助,请逐步完成。它有点老了,但应该这样做。

http://www.c-sharpcorner.com/blogs/how-to-upload-image-and-save-image-in-project-folder-in-mvc1

更新: 由于您需要在服务器之间共享,因此最好为此设置blob存储帐户。以下是对此的演练:

https://www.codeproject.com/articles/490178/how-to-use-azure-blob-storage-with-azure-web-sites