Restsharp: ๋Œ€์šฉ๋Ÿ‰ ํŒŒ์ผ ์—…๋กœ๋“œ ์‹œ ๋ฉ”๋ชจ๋ฆฌ ๋ถ€์กฑ ๋ฌธ์ œ

์— ๋งŒ๋“  2016๋…„ 10์›” 13์ผ  ยท  7์ฝ”๋ฉ˜ํŠธ  ยท  ์ถœ์ฒ˜: restsharp/RestSharp

RestSharp๋กœ ๋Œ€์šฉ๋Ÿ‰ ํŒŒ์ผ์„ ์—…๋กœ๋“œํ•  ๋•Œ ๋ฌด์ž‘์œ„๋กœ OutOfMemory ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค. ์ด๊ฒƒ์€ RestSharp๊ฐ€ ์žฅ๋ฉด ๋’ค์—์„œ HttpWebRequest๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๊ณ  AllowWriteStreamBuffering์˜ ๊ธฐ๋ณธ๊ฐ’์ด true์ด๊ธฐ ๋•Œ๋ฌธ์— ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค. ์ด๋Š” ์ฟผ๋ฆฌ๋ฅผ ์ˆ˜ํ–‰ํ•  ๋•Œ ์ „์ฒด ํŒŒ์ผ์ด ๋ฉ”๋ชจ๋ฆฌ์— ๋กœ๋“œ๋จ์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ 500MB ํŒŒ์ผ์„ ์—…๋กœ๋“œํ•˜๋Š” ๊ฒฝ์šฐ ๋ฌธ์ œ๊ฐ€ ๋ฉ๋‹ˆ๋‹ค.

ํ•„์š”ํ•œ ๊ฒƒ์€ AllowWriteStreamBuffering์„ false๋กœ ์„ค์ •ํ•˜๋Š” ๊ฒƒ์ด์ง€๋งŒ ์ง€๊ธˆ ๋‹น์žฅ์€ ConfigureWebRequest์—์„œ AllowWriteStreamBuffering์„ ๋ณ€๊ฒฝํ•  ๋ฐฉ๋ฒ•์ด ์—†์Šต๋‹ˆ๋‹ค.

๋‹ค์Œ๊ณผ ๊ฐ™์€ ๊ฒƒ์ด ์šฐ๋ฆฌ์˜ ํ•„์š”์— ์ถฉ๋ถ„ํ•  ๊ฒƒ์ž…๋‹ˆ๋‹ค.

var request = new RestRequest(Method.POST); request.AllowWriteStreamBuffering = false; request.Files.Add(new FileParameter // ...

help wanted good first issue

๊ฐ€์žฅ ์œ ์šฉํ•œ ๋Œ“๊ธ€

๋™์ผํ•œ ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•˜๊ณ  ์ฒ˜๋ฆฌ ๋ฐฉ๋ฒ•์ด ์—†์Šต๋‹ˆ๋‹ค.

๋ชจ๋“  7 ๋Œ“๊ธ€

์ฐธ๊ณ : .Net๊ณผ RestSharp 105.2.3์˜ ๋ฉ”๋ชจ๋ฆฌ ์••๋ ฅ์„ ํ…Œ์ŠคํŠธํ•  ์ˆ˜ ์žˆ๋„๋ก .AddFile์„ ์‚ฌ์šฉํ•  ๋•Œ ๋ฆด๋ฆฌ์Šค๋˜์ง€ ์•Š์€ ๋ฒ„๊ทธ ์ˆ˜์ •์ด ์žˆ์œผ๋ฏ€๋กœ ํ…Œ์ŠคํŠธ ๋ฐฉ๋ฒ•์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

// In the current implementation of RestSharp, there is an issue when using AddFile with a writer.
// It doesn't set the ContentLength, which break the queries with System.Net.ProtocolViolationException as we are not uploading 
// the expected amount of bytes. It's fixed in an yet unreleased version, so we are using the Files.Add manually for now.
var request = new RestRequest(Method.POST);
request.Files.Add(new FileParameter
{
                Name = "file",
                Writer = outStream => inStream.CopyTo(outStream),
                FileName = fileName,
                ContentLength = inStream.Length,
});

์ด์— ๋Œ€ํ•œ ์—…๋ฐ์ดํŠธ๊ฐ€ ์žˆ์Šต๋‹ˆ๊นŒ? ๋‚˜๋Š” ์ •ํ™•ํžˆ ๊ฐ™์€ ๋ฌธ์ œ๋ฅผ ๊ฒช๊ณ  ์žˆ์œผ๋ฉฐ RestClient ๋˜๋Š” RestRequest์—์„œ AllowWriteStreamBuffering์„ ๋…ธ์ถœํ•˜๋Š” ๊ฒƒ์ด ํ•ฉ๋ฆฌ์ ์œผ๋กœ ๋ณด์ž…๋‹ˆ๋‹ค. ๋‚ด๊ฐ€ ์•„๋Š” ํ•œ ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•์ด ์—†์Šต๋‹ˆ๋‹ค. ๋‚ด ์œ ์Šค ์ผ€์ด์Šค๋Š” ๋ณ‘๋ ฌ 100MB ํŒŒ์ผ์„ ๋ณด๋‚ด๊ณ  AllowWriteStreamBuffering์ด true์ด๋ฉด ๋ฉ”๋ชจ๋ฆฌ ๋ถ€์กฑ ์˜ˆ์™ธ๊ฐ€ ๋งค์šฐ ์ž์ฃผ ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค.

๋™์ผํ•œ ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•˜๊ณ  ์ฒ˜๋ฆฌ ๋ฐฉ๋ฒ•์ด ์—†์Šต๋‹ˆ๋‹ค.

์•„์ง ํ•ด๊ฒฐ๋๋‚˜์š”????

@AgentCoolDevil ๋„์™€์ฃผ์‹œ๊ฒ ์Šต๋‹ˆ๊นŒ? ํ’€ ๋ฆฌํ€˜์ŠคํŠธ๋ฅผ ํ•ฉ๋‹ˆ๋‹ค.

์ตœ์‹  ๋ฒ„์ „์—์„œ ์—ฌ์ „ํžˆ ์ด ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•˜๋Š” ์‚ฌ๋žŒ์ด ์žˆ์Šต๋‹ˆ๊นŒ?

@yvesmh ๊ฐ€ #1213์—์„œ ์ •๋‹นํ•˜๊ฒŒ ์–ธ๊ธ‰ํ–ˆ๋“ฏ์ด ์ด ๋ฌธ์ œ๋Š” WebRequest ์“ฐ๊ธฐ ์ŠคํŠธ๋ฆผ ๋ฒ„ํผ๋ง์„ ๋น„ํ™œ์„ฑํ™”ํ•˜์—ฌ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. IRestClient ์—์„œ ์›น ์š”์ฒญ ๊ตฌ์„ฑ์„ ์‚ฌ์šฉํ•˜์—ฌ ์ด๋Ÿฌํ•œ ๊ฒฝ์šฐ๋ฅผ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

client.ConfigureWebRequest(x => x.AllowWriteStreamBuffering = false);

์ด ํŽ˜์ด์ง€๊ฐ€ ๋„์›€์ด ๋˜์—ˆ๋‚˜์š”?
0 / 5 - 0 ๋“ฑ๊ธ‰