First of all, I'm new to both WCF and Dropzone JS, but I try to combine these two to create a simple image downloader. I have WCF working correctly for the metadata that I uploaded through it (so I know that it transferred the entire cross-domain correctly), but the Stream that I captured from Dropzone does not match the image that I reset, Actually, every single image fell, the result in the same encoded line on the server side ...
For example, I used this star image as a test, and by uploading the image to base64 online converter , I see that the beginning of the base64 line looks like this:
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOYAAADbCAMAAABOUB36AAAAwFBMVEX...
However, when I debug my WCF code, the converted base64 string looks like this:
LS0tLS0tV2ViS2l0Rm9ybUJvdW5kYXJ5T1RUV0I1RFZZdTVlM2NTNQ0KQ29udG...
This line above is the same as the one created for each image that I am trying to send.
So, now for all applicable code snippets. I have a simple web page in one project and WCF-related files in another project in the same solution.
Index.html:
<div class="col-lg-12"> <form action="http://localhost:39194/ImageRESTService.svc/AddImageStream/" class="dropzone" id="dropzone"></form> </div> ... Dropzone.options.dropzone = { maxFilesize: 10,
OperationContract:
[OperationContract] [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, UriTemplate = "AddImageStream/")] void AddImageStream(Stream img);
Implementation of AddImageStream:
public void AddImageStream(Stream img) { //try to save image to database byte[] buffer = new byte[10000]; int bytesRead, totalBytesRead = 0; string encodedData = ""; do { bytesRead = img.Read(buffer, 0, buffer.Length); encodedData = encodedData + Convert.ToBase64String(buffer, Base64FormattingOptions.InsertLineBreaks); totalBytesRead += bytesRead; } while (bytesRead > 0); }
Webconfig applicable fragments:
<services> <service name="ImageRESTService.ImageRESTService" behaviorConfiguration="serviceBehavior"> <endpoint address="" behaviorConfiguration="web" contract="ImageRESTService.IImageRESTService" binding="webHttpBinding" bindingConfiguration="webHttpBinding"></endpoint> </service> </services> <behaviors> <serviceBehaviors> <behavior name="serviceBehavior"> <serviceMetadata httpGetEnabled="false" /> <serviceDebug includeExceptionDetailInFaults="false" /> </behavior> </serviceBehaviors> <endpointBehaviors> <behavior name="web"> <webHttp /> </behavior> </endpointBehaviors> </behaviors> <standardEndpoints> <webHttpEndpoint> <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true" maxReceivedMessageSize="2147000000" /> </webHttpEndpoint> </standardEndpoints> <bindings> <webHttpBinding> <binding crossDomainScriptAccessEnabled="true" name="ImagesBinding" closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" /> <binding name="webHttpBinding" transferMode="Streamed" maxReceivedMessageSize="2147483647" maxBufferSize="10485760" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"> <readerQuotas maxStringContentLength="2147483647" maxArrayLength="1000000" /> </binding> </webHttpBinding>
The problem is visible when I break a fragment of an encoded string and does not match what was expected. If I copy the entire line to another online image that generates images from base64 strings, this is not a valid image. At the moment, I am stuck and could not determine why I can not read from dropzone.