question

35234478 avatar image
0 Votes"
35234478 asked NijilN-1016 published

asp.net core 3.1 HttpClient Error while copying content to a stream.

we have old file server with post and get requests to work with files. Now we need to bind our web server with old file server. But i'm getting Error while copying content to a stream. when PostAsync. What i'm doing wrong?

 [HttpPost]
     public async Task<string> UploadFile(string data) {
       dynamic execResult = null;
       TDecryptedCookie cookie = TAuthorization.GetCookieInfo(Request);
       dynamic json = TTools.Deserialize(data);
    
    
       string url = $"{TConst.FileServerHost}FileService/Upload?data={
                 { \"folder\":\"{json.F_Folder.Value}\", \"filename\":\"{json.F_FileName.Value}\",\"personID\":{cookie.PersonID}}}";
    
    
       dynamic result;
       var baseAddress = new Uri(url);
    
       try {
         using (var client = new HttpClient() { BaseAddress = baseAddress }) {
           client.DefaultRequestHeaders.Add("Authorization", Request.Headers["Authorization"].ToString()); 
           using var form = new MultipartFormDataContent();
    
           foreach (var file in Request.Form.Files) {
             //обработка файла
             byte[] fileBytes;
    
             using var ms = new MemoryStream();
             file.CopyTo(ms);
             fileBytes = ms.ToArray();
             using var fileContent = new ByteArrayContent(fileBytes);
             form.Add(fileContent, "file", file.FileName);
           }
           using var response = await client.PostAsync(baseAddress, form);   // <====== Error while copying content to a stream.
           response.EnsureSuccessStatusCode();
           var responseContent = await response.Content.ReadAsStringAsync();
           result = await TTools.Deserialize(responseContent);
    
              
       } catch (Exception e) {
         result = new { result = false, message = e.Message };
       }
       return result;
     }

dotnet-aspnet-core-general
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

35234478 avatar image
0 Votes"
35234478 answered WilsonJon-9504 published

resolved by reading innerexception not e.Message

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Can you share what the Inner Exception was?

0 Votes 0 ·
NijilN-1016 avatar image
0 Votes"
NijilN-1016 answered NijilN-1016 published

Can you pls share the innerexception and the solution.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.