locked
ReadAsMultipartAsync In Asp.net Core mvc RRS feed

  • Question

  • User338455301 posted

    Hi 
    i want use below codes  in .net core but not exsist , how to use it or replace it with other way ?

    	private async Task<bool> readPart(MultipartFormDataStreamProvider provider)
    		{
    			try
    			{
    				await Request.Content.ReadAsMultipartAsync(provider); // this code
    ....
    ....
    }
    }


     

    Saturday, September 26, 2020 10:56 AM

All replies

  • User475983607 posted

    Your question makes no sense.  What are you trying to do?  If you are trying to return multiple files, then that's not possible.  You need to zip the files into on file and return the zipped file.

    Saturday, September 26, 2020 11:01 AM
  • User338455301 posted

    i can't access to ReadAsMultiAsync and its not exists namespace Content.Request.ReadAsMultiAsync  in .net core

    Saturday, September 26, 2020 11:08 AM
  • User475983607 posted

    Your code is incomplete, you have not provided that actual error, and it looks like you are trying to convert MVC5 into Core.  The community cannot read your mind.  Are you trying to upload files? 

    Explain the goal and include all the code relevant code so the community can reproduce the issue.  Please do not make the community guess what you are trying to do.

    The openly published ASP.NET Core documentation illustrates how to read multiple upload files.

    https://docs.microsoft.com/en-us/aspnet/core/mvc/models/file-uploads?view=aspnetcore-3.1

    Saturday, September 26, 2020 11:23 AM
  • User338455301 posted

    i want use resumable/chunck upload  with resumable.js in .net core 
    but source code is for .net and some part of source code is not work in asp.net core
    i just want migrate/change these codes for asp.net core 

    Resumable js / .Net Controllers

    i change more codes for .net core  but some codes cant change it , example : 

    	private async Task<bool> readPart(MultipartFormDataStreamProvider provider)
    		{
    			try
    			{
    				await Request.Content.ReadAsMultipartAsync(provider);
    				ResumableConfiguration configuration = GetUploadConfiguration(provider);
    				int chunkNumber = GetChunkNumber(provider);
    
    				// Rename generated file
    				MultipartFileData chunk = provider.FileData[0]; // Only one file in multipart message
    				RenameChunk(chunk, chunkNumber, configuration.Identifier);
    
    				// Assemble chunks into single file if they're all here
    				TryAssembleFile(configuration);
    				return true;
    			}
    			catch {
    				return false;
    			}
    		}


     

    Saturday, September 26, 2020 11:58 AM
  • User475983607 posted

    Read the link in my previous post!  The link clearly and openly explains how to read large amounts of data.  

    Saturday, September 26, 2020 12:19 PM
  • User-474980206 posted

    the MultipartFormDataStreamProvider was not parted to .net core. Typically you should use the IFormFile interface to get a stream to the request file stream.

    note: The server does not know the client is using chunks. it looks the same as if the browser did the post.

    Saturday, September 26, 2020 11:01 PM
  • User338455301 posted

    ok , i must use ifrom File
    but What is the equivalent of this code in .net core?

    	await Request.Content.ReadAsMultipartAsync(provider);

     

    Sunday, September 27, 2020 5:23 AM
  • User-474980206 posted

    There isn’t one. You must rewrite your code. See docs for multipart support. You are probably interested in the uploadinglsrge files with streaming section.

    https://docs.microsoft.com/en-us/aspnet/core/mvc/models/file-uploads?view=aspnetcore-3.1

    Monday, September 28, 2020 2:43 PM