简体   繁体   中英

Unable to upload file to server with wcf

在此处输入图片说明 I am trying to upload files from react app to server via wcf service. The code is working fine on local server. The service is hosted on godaddy servers. When I try to upload file the server gives error 400 bad request. The code is working fine on local server and creating folder and saving the file in the right folder. What other details I should provide.

public void UploadFile(Stream stream)
    {

        MultipartParser parser = new MultipartParser(stream);
        string uploadpath = HttpContext.Current.Server.MapPath("~/images/");

        if (parser.Success)
        {
            string filename = HttpUtility.UrlDecode(parser.Filename);
            File.WriteAllBytes(uploadpath + filename, parser.FileContents);
        }
        else
        {
            Console.WriteLine("error");
        } 
        }
      }

<?xml version="1.0"?>

<configuration>

  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true"/>
  </appSettings>
<system.web>
  <compilation debug="true" targetFramework="4.6.1" />
  <httpRuntime targetFramework="4.6.1"/>
<membership>
      <providers>
        <clear />
        <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
      </providers>
    </membership>
    <roleManager enabled="true">
      <providers>
        <clear />
        <add connectionStringName="ApplicationServices" applicationName="/" name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" />
        <add applicationName="/" name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" />
      </providers>
    </roleManager>
  <trust level="Full" originUrl=""/>
  <customErrors mode="Off"/>
</system.web>
<system.serviceModel>
  <behaviors>
    <serviceBehaviors>
      <behavior name="serviceBehaviors">
        <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
        <serviceMetadata httpGetEnabled="true" />
        <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
        <serviceDebug includeExceptionDetailInFaults="true"/>
      </behavior>
    </serviceBehaviors>
    <endpointBehaviors>
      <behavior name="web" >
        <webHttp></webHttp>
      </behavior>
    </endpointBehaviors>
  </behaviors>
  <bindings>
    <webHttpBinding>
      <binding name="largeMessage" maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" closeTimeout="00:03:00" openTimeout="00:03:00" receiveTimeout="00:10:00" sendTimeout="00:03:00">
        <readerQuotas maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" />
        <security mode="None"/>
      </binding>
    </webHttpBinding>
  </bindings>
  <services>
    <service name="mailService.Service1" behaviorConfiguration="serviceBehaviors">
      <endpoint address="" contract="mailService.IService1" binding="webHttpBinding" bindingConfiguration="largeMessage" behaviorConfiguration="web"></endpoint>
      <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
    </service>
  </services>
  <protocolMapping>
    <add binding="basicHttpsBinding" scheme="https"  />
  </protocolMapping>
  <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
<system.webServer>
  <modules runAllManagedModulesForAllRequests="true"/>
  <!--
      To browse web app root directory during debugging, set the value below to true.
      Set to false before deployment to avoid disclosing web app folder information.
    -->
  <directoryBrowse enabled="true"/>
<security>

</security>
</system.webServer>
</configuration>

The file size is not big 127kb only

在此处输入图片说明

Postman is showing that access denied to the path.

更改了服务器上图像文件夹的权限,我工作了。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM