مرجع تخصصی برنامه نویسان

انجمن تخصصی برنامه نویسان فارسی زبان

کاربر سایت

source

عضویت از 1395/11/13

آپلود تصویر به صورت Byte

  • چهارشنبه 2 مرداد 1398
  • 12:01
تشکر میکنم

سلام

میخوام تصویر/ تصاویر رو به صورت Byte به سرور ارسال کنم و بعد ذخیره کنم تووی فولدر!

ممنونم

پاسخ های این پرسش

تعداد پاسخ ها : 2 پاسخ
کاربر سایت

رضا نصیری

عضویت از 1392/10/01

  • چهارشنبه 2 مرداد 1398
  • 16:37

سلام به Base64 تبدیل کن و بصورت رشته به سرور بفرست و اونجا از Base64 به Image تبدیل کن و ذخیره کن

کاربر سایت

source

عضویت از 1395/11/13

  • چهارشنبه 30 مرداد 1398
  • 00:46

سلام

ارور [object,object] بر میگردونه.

        [HttpPost]
        public JsonResult upload(string base64image)//or (Ima a) ,it works too
        {

            try
            {
                
            base64image = base64image.Replace("data:image/jpg;base64,", "");


            byte[] imageBytes = Convert.FromBase64String(base64image);
                MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length);

                // Convert byte[] to Image
                ms.Write(imageBytes, 0, imageBytes.Length);
                System.Drawing.Image image = System.Drawing.Image.FromStream(ms, true);
                image.Save(Server.MapPath("/001/img.jpg"), System.Drawing.Imaging.ImageFormat.Jpeg);

                return Json("1");

            }
            catch (Exception e)
            {
                return Json(e);

            }
        }

اینم فایل کانفیگمه:

      <appSettings>
    <add key="webpages:Version" value="3.0.0.0"/>
    <add key="webpages:Enabled" value="false"/>
    <add key="ClientValidationEnabled" value="true"/>
    <add key="UnobtrusiveJavaScriptEnabled" value="true"/>
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.6.1"/>
    <httpRuntime targetFramework="4.6.1" maxRequestLength="2147483641" maxQueryStringLength="32768" maxUrlLength="65536" executionTimeout="10000" />
  </system.web>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35"/>
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35"/>
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/>
        <bindingRedirect oldVersion="1.0.0.0-5.2.3.0" newVersion="5.2.3.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs"
        type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701"/>
      <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb"
        type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+"/>
    </compilers>
  </system.codedom>

  <system.webServer>
    <security>
      <requestFiltering>
        <requestLimits   maxAllowedContentLength="1073741824" maxQueryString="32768"/>
        <!--کنترل حجم فایل ارسالی به سرور-->
      </requestFiltering>
    </security>
  </system.webServer>
  <system.web>
    <customErrors mode="Off" />
    <sessionState mode="InProc" timeout="500"></sessionState>
  </system.web>

این هم نتیجه ی فایرباگ هست:

        <html>
    <head>
        <title>A circular reference was detected while serializing an object of type 'System.Reflection.RuntimeModule'.</title>
        <meta name="viewport" content="width=device-width" />
        <style>
         body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;} 
         p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px}
         b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px}
         H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
         H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
         pre {font-family:"Consolas","Lucida Console",Monospace;font-size:11pt;margin:0;padding:0.5em;line-height:14pt}
         .marker {font-weight: bold; color: black;text-decoration: none;}
         .version {color: gray;}
         .error {margin-bottom: 10px;}
         .expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }
         @media screen and (max-width: 639px) {
          pre { width: 440px; overflow: auto; white-space: pre-wrap; word-wrap: break-word; }
         }
         @media screen and (max-width: 479px) {
          pre { width: 280px; }
         }
        </style>
    </head>

    <body bgcolor="white">

            <span><H1>Server Error in '/' Application.<hr width=100% size=1 color=silver></H1>

            <h2> <i>A circular reference was detected while serializing an object of type 'System.Reflection.RuntimeModule'.</i> </h2></span>

            <font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif ">

            <b> Description: </b>An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

            <br><br>

            <b> Exception Details: </b>System.InvalidOperationException: A circular reference was detected while serializing an object of type 'System.Reflection.RuntimeModule'.<br><br>

            <b>Source Error:</b> <br><br>

            <table width=100% bgcolor="#ffffcc">
               <tr>
                  <td>
                      <code>

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.</code>

                  </td>
               </tr>
            </table>

از فایل ریدر استفاده میکنم برای تبدیل به base64 .

بعد موقع ارسال آرایه رو تبدیل به string میکنم. tostring();

اماموقع دریافت این مشکل بوجود میاد. 

کاربرانی که از این پست تشکر کرده اند

هیچ کاربری تا کنون از این پست تشکر نکرده است

اگر نیاز به یک مشاور در زمینه طراحی سایت ، برنامه نویسی و بازاریابی الکترونیکی دارید

با ما تماس بگیرید تا در این مسیر همراهتان باشیم :)