Uploading large files from android to c# WCF Rest

2019-04-09 18:59发布

i am developing an android application where i can upload video,audio and images from android device to WCF REST Service. it is uploading a video file of 10MB size perfectly, but when i tried to upload a video file of 1GB it is not uploading to server. i want to make an application where i can upload a file size upto 3gb to 4gb.how can i achieve this can anyone please guide me to achieve this scenario.

wcf Service Code :

public string PostImage(Stream stream)
        {
MultipartParser parser = new MultipartParser(stream);

            if (parser.Success)
            {
                string fileName = parser.Filename;
                string contentType = parser.ContentType;
                byte[] fileContent = parser.FileContents;
                FileStream fileToupload = new FileStream("D:\\FileUpload\\" + fileName, FileMode.Create);
                fileToupload.Write(fileContent, 0, fileContent.Length);
                fileToupload.Close();
                fileToupload.Dispose();
                stream.Close();
                return "Success !!!";
            }
            else
            {
                return "Exception!!!";
            }
        }

web.config file:

<configuration>

  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5"/>
  </system.web>
  <system.serviceModel>
    <services>
      <service name="Upload.Service1" behaviorConfiguration="default">
        <endpoint address="" behaviorConfiguration="web" binding="webHttpBinding" bindingConfiguration="RestBinding" name="Service1" contract="Upload.IService1" />
      </service>   
    </services>
    <behaviors>
      <endpointBehaviors>
        <behavior name="web">
          <webHttp/>
        </behavior> 
      </endpointBehaviors>

      <serviceBehaviors>
        <behavior name="default">
          <dataContractSerializer maxItemsInObjectGraph="2147483647" />

          <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="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="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <webHttpBinding>
        <binding name="RestBinding"  maxReceivedMessageSize="2147483647"  maxBufferSize="2147483647">
          <readerQuotas maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="544096" />
          <security mode="None">
          </security>
        </binding>

      </webHttpBinding>
    </bindings>
    <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"/>
  </system.webServer>

</configuration>

My Android Code:

        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httpost = new HttpPost("http://192.169.3.34/Service1.svc/upload");
        MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
        entity.addPart("fileContents", new FileBody(new File("/mnt/sdcard/hi.mp4")));
        httpost.setEntity(entity);
        HttpResponse response;
        response = httpclient.execute(httpost);

i am getting the status code as 404 when i tried to upload a file of 1GB.

where i need to do changes to make my code to upload a file size of 2gb to 5gb. can anyone please help me out in solving the issue.

0条回答
登录 后发表回答