HttpClient StreamContent appends file name twice

I use the Microsoft Http Client Libraries to make a multi-page request from Windows Phone 8 to the server. It contains the contents of a string having a json string, and streaming content having an image stream. Now I get the status "OK" and request requests on the server. but the logs say that the server cannot get the image file name.

content.Add(new StreamContent(photoStream), "files", fileName);

where photoStream is the image stream, “files” is the name of the content, and file name is the name of the image file.

Thus, the value of the header should be:

Content-Disposition: form-data; name=files; filename=image123.jpg

but actually it is:

Content-Disposition: form-data; name=files; filename=image123.jpg; filename*=utf-8''image123.jpg

Why is he adding the " ; filename*=utf-8''image123.jpg" part . This is problem?

Please let me know any reasons / possibilities that I cannot download an image from WP8.

+3
3
using (var content = new MultipartFormDataContent())
{
    content.Add(CreateFileContent(imageStream, fileName, "image/jpeg"));
}

private StreamContent CreateFileContent(Stream stream, string fileName, string contentType)
{
    var fileContent = new StreamContent(stream);
    fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data") 
    { 
        Name = "\"files\"", 
        FileName = "\"" + fileName + "\""
    };
    fileContent.Headers.ContentType = new MediaTypeHeaderValue(contentType);            
    return fileContent;
}
+8

, HttpStringContent StreamContent, Damith , :

var fd = new Windows.Web.Http.HttpMultipartFormDataContent();
var file = new Windows.Web.Http.HttpStringContent(fs);
file.headers.contentType = new Windows.Web.Http.Headers.HttpMediaTypeHeaderValue("application/octet-stream");
fd.add(file);
file.headers.contentDisposition = new Windows.Web.Http.Headers.HttpContentDispositionHeaderValue.parse("form-data; name=\"your_form_name\"; filename=\"your_file_name\"");
Hide result

: , contentDisposition , "form-data".

0

:

HttpContent fileStreamContent = new StreamContent(new FileStream(xmlTmpFile, FileMode.Open));
var formData = new MultipartFormDataContent();
formData.Add(fileStreamContent, "xml", Path.GetFileName(xmlTmpFile));
fileStreamContent.Headers.ContentDisposition.FileNameStar = null;
-1

Source: https://habr.com/ru/post/1684714/


All Articles