locked
UWP and .Net Core API Upload RRS feed

  • Question

  • Hi,

    While developing a UWP application in integration with .Net Core API, I am getting an issue while uploading more then 20 MB file. Following are UWP code (Portable library) to invoke API:

    public async Task<ApiResult<string>> UploadAsync(string url, object obj, string fileName, byte[] file)
            {
                using (var client = CreateHttpClientForUpload())
                {

                        var form = new MultipartFormDataContent();
                        form.Add(new ByteArrayContent(file, 0, file.Count()), "file", fileName);

                        var response = await client.PostAsync($"{url}/upload", form); //No response if filesize exceeds 20 MB

                        return await ReadResponseAsync<string>(response);
                   
                }
            }

    Following are the .Net Core API code:

            [HttpPost("upload")]
            public async Task<IActionResult> Upload(IFormFile file)
            {
                if (file == null)
                    return new BadRequestResult();

                var path = await OnUpload(file);
                if (string.IsNullOrEmpty(path))
                    throw new InvalidOperationException();

                return new JsonResult(path);
            }

    Any guess?


    &lt;p&gt;Cheers,&lt;/p&gt; &lt;p&gt;Sumit Chauhan&lt;/p&gt; &lt;p&gt;Microsoft Certified Professional and Microsoft Partner&lt;/p&gt; &lt;b&gt;Blog:&lt;/b&gt; &lt;a href=&quot;http://www.sumitblogs.com/feed/&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://aka.ms/gmvm2k&quot; border=&quot;0&quot;&gt;&lt;/a&gt; &lt;a href=&quot;http://www.sumitblogs.com&quot;&gt;http://www.sumitblogs.com&lt;/a&gt;

    Tuesday, September 27, 2016 11:59 AM

Answers

  • Hi Sumit C,

    >>” Please share if there is any working sample or where I can see similar approach implemented.”

    Here’s a code sample about “Universal Windows Apps: Upload and download files from Azure Storage” for your reference.

    By the way, if you want to know how to implement using "Xamarin Portable Library", please post your question on Xamarin forum: https://forums.xamarin.com/discussions/tagged/uwp/p1

    Best Regards,

    Xavier Eoro


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, September 30, 2016 8:33 AM

All replies

  • Hi Sumit C,

    The HttpClient is recommended to transfer smaller resource (i.e. couple KB). And with large files it’s better to use BackgroundTransfer APIs: https://msdn.microsoft.com/library/windows/apps/br207242

    Please refer to this article "Background transfer API in universal Windows apps: what you need to know " for more details: https://blogs.windows.com/buildingapps/2014/04/25/background-transfer-api-in-universal-windows-apps-what-you-need-to-know/#7vxG14wW8MWmDWVT.97

    Best Regards,

    Xavier Eoro

     

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, September 28, 2016 8:22 AM
  • Thanks Xavier for your response. I tried using suggested approach but there seems to lot of DLL compatibility issue. Here is the scenario I want to implement using "Xamarin Portable Library". I want to upload a large video to Azure Blob using shared code from UWP application. Please share if there is any working sample or where I can see similar approach implemented. Other alternatives may also help (but needs to be Microsoft specific).

    &lt;p&gt;Cheers,&lt;/p&gt; &lt;p&gt;Sumit Chauhan&lt;/p&gt; &lt;p&gt;Microsoft Certified Professional and Microsoft Partner&lt;/p&gt; &lt;b&gt;Blog:&lt;/b&gt; &lt;a href=&quot;http://www.sumitblogs.com/feed/&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;http://aka.ms/gmvm2k&quot; border=&quot;0&quot;&gt;&lt;/a&gt; &lt;a href=&quot;http://www.sumitblogs.com&quot;&gt;http://www.sumitblogs.com&lt;/a&gt;

    Thursday, September 29, 2016 1:13 PM
  • Hi Sumit C,

    >>” Please share if there is any working sample or where I can see similar approach implemented.”

    Here’s a code sample about “Universal Windows Apps: Upload and download files from Azure Storage” for your reference.

    By the way, if you want to know how to implement using "Xamarin Portable Library", please post your question on Xamarin forum: https://forums.xamarin.com/discussions/tagged/uwp/p1

    Best Regards,

    Xavier Eoro


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, September 30, 2016 8:33 AM