-2

I sign a file with a secure digital signature using SHA256 technology and then want to send the file in C# code to the WEB API according to FILESTREAM The problem is that the file goes wrong, what can solve the problem? This is my code:

    public static async Task<String> SigeFile(Microsoft.AspNetCore.Http.IFormFile file, string PathFile, string fileName, string newPath, string newName)
    {
        string UrlSign = Properties.Settings.Default.UrlWebSigeApi + "SignFile";
        using (var client = new HttpClient())
        using (FileStream fs = File.Open(PathFile, FileMode.Open))
        {
            HttpContent fileStreamContent = new StreamContent(fs);
            fileStreamContent.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("form-data") { Name = "file", FileName = fileName };
            fileStreamContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/octet-stream");

            using (var formData = new MultipartFormDataContent())
            {
                formData.Add(fileStreamContent);
                formData.Add(new StringContent(newPath), "newPath");
                formData.Add(new StringContent(newName), "newFileName");

                //send to URL
                try
                {
                    HttpResponseMessage response = client.PostAsync(UrlSign, formData).Result;
                    var contents = await response.Content.ReadAsStringAsync();
                    return contents.ToString();
                }
                catch (Exception e)
                {
                    CustomLog.MyLogger.error(e);
                    return e.Message;
                }
            }
        }

    }
D Tz
  • 1
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Aug 30 '23 at 13:47

0 Answers0