Click here to Skip to main content
15,881,715 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to use Encoding.unicode in TransferUtilityUploadRequest in dotnet


The below code is working if i use response
Encoding encoding = Encoding.UTF8;
            var bytes = encoding.GetBytes("José Nuñez");
            MemoryStream stream = new MemoryStream(bytes);
            StreamReader reader = new StreamReader(stream);
            stream.Seek(0, SeekOrigin.Current);
            Response.Clear();
            Response.Buffer = true;
            Response.AddHeader("content-disposition", string.Format("attachment;filename={0}.csv", "filename"));
            Response.Charset = encoding.EncodingName;
            Response.ContentType = "application/text";
            Response.ContentEncoding = Encoding.Unicode;
            Response.Output.Write(reader.ReadToEnd());
            Response.Flush();
            Response.End();


But i want add header to
TransferUtilityUploadRequest 


What I have tried:

I have tried to add header
uploadRequest.Headers.ContentEncoding = Encoding.Unicode;
but not working
TransferUtilityUploadRequest uploadRequest = new TransferUtilityUploadRequest();
                        uploadRequest.BucketName = sourceBucketName.ConfigValue.ToString();
                        uploadRequest.Key = fileFullName;
                        uploadRequest.Headers.ContentEncoding = Encoding.Unicode;

                        Stream tmpStream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(downloadData)); 
                        tmpStream.Seek(0, SeekOrigin.Begin);
                        StreamReader sReaderData = new StreamReader(tmpStream);
                        string viewTheData = sReaderData.ReadToEnd();
Posted
Updated 24-Jan-19 9:33am
v2
Comments
MadMyche 24-Jan-19 11:09am    
"but not working" really says nothing to us. Is there an error thrown? Is incorrect data being sent?

1 solution

I'm not even sure that Headers.ContentEncoding is a standard header. There is a Content-Encoding header but that is related to compression (eg gzip, deflate).

It looks like you may have a problem with Response.Charset = encoding.EncodingName;, which would give out the "friendly name" as opposed to the IANA registry name. Try replacing the encoding.EncodingName with encoding.WebName, and getting rid of the other header.

Reference: Encoding.WebName Property (System.Text) | Microsoft Docs[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900