【问题标题】:Website with Azure Mobile Backend带有 Azure 移动后端的网站
【发布时间】:2018-01-28 08:45:44
【问题描述】:

我目前正在使用带有 azure 后端的 xamarin 表单制作应用程序,我的应用程序的功能之一是能够将长视频上传到 azure blob 存储,但是由于这些视频中的大多数将是大文件并且是在计算机上编辑我认为最好能够使用网站通过计算机上传视频文件,但是是否可以将网站连接到我的应用程序正在使用的同一个 azure 移动后端,如果可以,我会怎么做那,如果没有其他好的选择?

【问题讨论】:

    标签: azure xamarin xamarin.forms


    【解决方案1】:

    相信您熟悉 Asp.Net WebApi 2、OData V3、MVC4+、EF6 和 IIS 托管。如果是这样,那么只需构建自托管 WebApi 项目并编写一个 Web api 控制器以使用 Async 和 Stream 上传文件并在 Azure 中托管该项目。如果需要,您可以使用计算机(应该有可以在 MVC4 中构建并使用相同的 Web api 控制器的后端仪表板)或移动应用程序上传文件。

    有关如何构建 Web Api 的示例,请查看 link 和 Post 控制器

    public async Task<List<string>> PostAsync()
    {
        if (Request.Content.IsMimeMultipartContent())
        {
            string uploadPath = HttpContext.Current.Server.MapPath("~/uploads");
    
            MyStreamProvider streamProvider = new MyStreamProvider(uploadPath);
    
            await Request.Content.ReadAsMultipartAsync(streamProvider);
    
            List<string> messages = new List<string>();
            foreach(var file in streamProvider.FileData)
            {
                FileInfo fi = new FileInfo(file.LocalFileName);
                messages.Add("File uploaded as " + fi.FullName + " (" + fi.Length + " bytes)");
            }
    
            return messages;
        }
        else
        {
            HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.BadRequest, "Invalid Request!");
            throw new HttpResponseException(response);
        }
    }
    

    【讨论】:

    • 如果我创建一个 ASP Web 应用程序,我可以将它连接到我的移动后端,它应该可以与移动应用程序一起正常工作?
    • 是的,它有效。您可以使用 Webservice 并实现 Post 方法来上传视频文件,其余功能将保持原样。
    • 所以只需将 asp.net 应用程序连接到后端,就像我使用移动应用程序所做的那样
    猜你喜欢
    • 1970-01-01
    • 2015-05-30
    • 1970-01-01
    • 1970-01-01
    • 2014-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多