{"id":551,"date":"2022-09-28T09:36:23","date_gmt":"2022-09-28T00:36:23","guid":{"rendered":"https:\/\/sumomo.ohwaki.jp\/wordpress\/?p=551"},"modified":"2022-09-28T09:36:23","modified_gmt":"2022-09-28T00:36:23","slug":"blazor%e3%81%a7%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab%e3%83%80%e3%82%a6%e3%83%b3%e3%83%ad%e3%83%bc%e3%83%89","status":"publish","type":"post","link":"https:\/\/sumomo.ohwaki.jp\/wordpress\/?p=551","title":{"rendered":"blazor\u3067\u30d5\u30a1\u30a4\u30eb\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9"},"content":{"rendered":"\n<p>blazor\u306b\u306fwebapp\u306eFileResult\u3092\u4f7f\u7528\u3057\u305fPostBack\u3088\u3046\u306a\u52d5\u7684\u306b\u30d5\u30a1\u30a4\u30eb\u30b3\u30f3\u30c6\u30f3\u30c4\u3092\u4f5c\u6210\u3057\u3066\u3001\u30d5\u30a1\u30a4\u30eb\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3055\u305b\u308b\u4ed5\u7d44\u307f\u304c\u7121\u3044\u3002<\/p>\n\n\n\n<p>\u3067\u306f\u3001\u3069\u3046\u3084\u3063\u3066\u30d5\u30a1\u30a4\u30eb\u30b3\u30f3\u30c6\u30f3\u30c4\u3092\u4f5c\u6210\u3057\u3066\u3001\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3055\u305b\u308b\u304b\u3092\u8abf\u3079\u3066\u307f\u305f\u3002<\/p>\n\n\n\n<p>\u666e\u901a\u306b\u8003\u3048\u308b\u3068\u30011\u756a\u7c21\u5358\u306a\u306e\u306f\u3001\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u3067\u30b3\u30f3\u30c6\u30f3\u30c4\u3092\u4f5c\u6210\u3057\u3066\u3001Data URL\u306b\u5909\u63db\u3057\u3001\u305d\u306e\u30ea\u30f3\u30af\u3092\u8868\u793a\u3055\u305b\u308b\u65b9\u6cd5\u3060\u304c\u3001\u3053\u308c\u3060\u3068\u3001\u4f5c\u6210\u306e\u30c8\u30ea\u30ac\u30fc\u3068\u30ea\u30f3\u30af\u3092\u30af\u30ea\u30c3\u30af\u3059\u308b\u3068\u3044\u3046\u30012\u30a2\u30af\u30b7\u30e7\u30f3\u304c\u5fc5\u8981\u306b\u306a\u308b\u3002<\/p>\n\n\n\n<p>\u7d50\u5c40\u3001\u4f5c\u6210\u30c8\u30ea\u30ac\u30fc(\u4f8b\u3048\u3070\u30dc\u30bf\u30f3\u30af\u30ea\u30c3\u30af)\u3067\u30d5\u30a1\u30a4\u30eb\u306e\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u307e\u3067\u3001\u884c\u3046\u306b\u306f\u3001Javascript\u306e\u52a9\u3051\u3092\u501f\u308a\u308b\u3053\u3068\u306b\u306a\u308b\u3002<\/p>\n\n\n\n<p>\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u611f\u3058\u3067\u53ef\u80fd\u3060\u304c\u3001\u30b5\u30a4\u30ba\u5236\u9650(MS\u306e\u30b5\u30a4\u30c8\u3067\u306f250Mbytes\u4ee5\u4e0b\u3068\u8a18\u8ff0\u3055\u308c\u3066\u3044\u305f)\u304c\u3042\u308b\u3088\u3046\u3060\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism undefined-numbers lang-js\" data-file=\"\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u30d8\u30eb\u30d1\u30fc(JS)\" data-lang=\"JavaScript\"><code>\/\/\n\/\/  \u30d5\u30a1\u30a4\u30eb\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3059\u308bJS\u30d8\u30eb\u30d1\u30fc\n\/\/      \u3084\u3063\u3066\u3044\u308b\u3053\u3068\u306f\u5358\u7d14\u3067\u3001Stream\u304b\u3089Blob\u3092\u4f5c\u6210\u3057\u3066\u305d\u306eurl\u3092\u3082\u3063\u305f\u3001\n\/\/      a\u30bf\u30b0\u3092\u751f\u6210\u3057\u3001a\u30bf\u30b0\u306b\u5bfe\u3057\u3066click\u30a4\u30d9\u30f3\u30c8\u3092\u767a\u751f\u3055\u305b\u305f\u5f8c\u3001a\u30bf\u30b0\u3068data url\n\/\/      \u306b\u5272\u3044\u3066\u3044\u308b\u30ea\u30bd\u30fc\u30b9\u3092\u958b\u653e\u3002\n\/\/      \u7d50\u69cb\u826f\u304f\u4f7f\u3046\u624b\u6bb5\u3060\u306d\u3002blazor\u72ec\u81ea\u306e\u70b9\u306f.NET\u306eStream\u3092\n\/\/      Javascript\u7528\u306bWrapping\u3057\u3066arrayBuffer\u3092\u53d6\u5f97\u3057\u3066\u3044\u308b\u70b9\u3050\u3089\u3044\u3002\nvar mylibrary = {\n    DownloadFile : async (StreamRef, FileName) =&gt; {\n        const arrayBuffer = await StreamRef.arrayBuffer();\n        const blob = new Blob([arrayBuffer]);\n        const url = URL.createObjectURL(blob);\n        const anchorElement = document.createElement(&#39;a&#39;);\n        anchorElement.href = url;\n        anchorElement.download = FileName ?? &#39;&#39;;\n        anchorElement.click();\n        anchorElement.remove();\n        URL.revokeObjectURL(url);\n    }\n};<\/code><\/pre><\/div>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism undefined-numbers lang-csharp\" data-file=\"\u30b3\u30f3\u30c6\u30f3\u30c4\u4f5c\u6210(C#)\" data-lang=\"C#\"><code>using(MemoryStream mstm = new MemoryStream()) {\n\t\/\/ \u30b3\u30f3\u30c6\u30f3\u30c4\u4f5c\u6210\n\tawait mstm.FlushAsync();\n\t\/\/ \u5ff5\u306e\u305f\u3081\n\tmstm.Seek(0L,SeekOrigin.Begin);\n\t\/\/ Javascript\u306b\u6e21\u3059\u305f\u3081\u306eStream\u30ea\u30d5\u30a1\u30ec\u30f3\u30b9\u4f5c\u6210\n\tusing var stmRef = new DotNetStreamReference(stream: mstm);\n\t\/\/ Javascript\u547c\u51fa\n\tawait JSRuntime.InvokeVoidAsync(&quot;mylibrary.DownloadFile&quot;,stmRef,FileName);\n}<\/code><\/pre><\/div>\n\n\n\n<p>\u5927\u304d\u3044\u30d5\u30a1\u30a4\u30eb\u306e\u5834\u5408\u306f\u3001\u7269\u7406\u7684\u306b\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3057\u3066\u3001\u305d\u306e\u30ea\u30f3\u30af\u3067a\u30bf\u30b0\u4f5c\u6210\u304a\u3088\u3073\u3001\u30af\u30ea\u30c3\u30af\u30fb\u30fb\u30fb\u3068\u3044\u3046\u5f62\u3092\u53d6\u308c\u3068\u306e\u3053\u3068\u3002<\/p>\n\n\n\n<p>\u4f55\u304b\u4ed6\u306b\u826f\u3044\u65b9\u6cd5\u306f\u7121\u3044\u3082\u306e\u3060\u308d\u3046\u304b\u30fb\u30fb\u30fb<\/p>\n\n\n\n<p>\u30d5\u30a1\u30a4\u30eb\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u306e\u6a19\u6e96\u7684\u306a\u4ed5\u7d44\u307f\u3092blazor\u5185\u3067\u5b9a\u7fa9\u3057\u3066\u6b32\u3057\u3044\u3082\u306e\u3060\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>blazor\u306b\u306fwebapp\u306eFileResult\u3092\u4f7f\u7528\u3057\u305fPostBack\u3088\u3046 &hellip; <a href=\"https:\/\/sumomo.ohwaki.jp\/wordpress\/?p=551\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18,12,10,9,24,23,4],"tags":[],"class_list":["post-551","post","type-post","status-publish","format-standard","hentry","category-net","category-asp-net-core","category-blazor","category-c","category-javascript","category-web","category-4"],"_links":{"self":[{"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/551","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=551"}],"version-history":[{"count":2,"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/551\/revisions"}],"predecessor-version":[{"id":553,"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/551\/revisions\/553"}],"wp:attachment":[{"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=551"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=551"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sumomo.ohwaki.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=551"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}