I am developing an Android application where I can upload video, audio and images from an Android device to the WCF REST service. it automatically uploads a 10 MB video file, but when I tried to upload a 1 GB video file, it does not upload to the server. I want to create an application in which I can upload a file size of up to 3gb to 4gb . How can I achieve this, can someone help me 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" /> <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/> <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"/> <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 get a status code as 404 when I tried to upload a 1 GB file.
where do I need to make changes to get my code to upload a file from 2 to 5 GB in size. can anyone help me in solving the problem.
source share