Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HttpClient StreamContent append filename twice

I am using Microsoft Http Client Libraries to make a multipart request from Windows Phone 8 to the server. It contains a String content having json string and a Stream Content having image stream. Now i get the status OK and request hits on the server. but the logs says the server is not able to get the file name of the image.

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

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

So the header value must 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 it is appending the "; filename*=utf-8''image123.jpg" part. Is it an issue?

Please let me know any reasons/possibility that i am not able to upload image from WP8.

like image 646
Deeps Avatar asked Dec 05 '13 08:12

Deeps


1 Answers

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;
}
like image 193
Damith Avatar answered Oct 18 '22 08:10

Damith