Finn
Finn

Reputation: 952

Alfresco REST API:Data Size Limit?

I am developing REST based webservices in alfresco for data transfer & want to know what is the maximum amount of data i can send/get thru REST protocol?

Any reference would be very helpful.

Regards.

Upvotes: 1

Views: 2234

Answers (1)

Jobert Enamno
Jobert Enamno

Reputation: 4461

The max amount of data is as large as 2147000000. That's why if your data is large enough it is advisable to stream it to post to your REST service. Here's an example.

Sender/ Uploader Application or Client

        var sb = new StringBuilder();
        sb.Append("Just test data. You can send large one also");
        var postData = sb.ToString();
        var url = "REST Post method example http://localhost:2520/DataServices/TestPost";
        var memoryStream = new MemoryStream();
        var dataContractSerializer = new DataContractSerializer(typeof(string));
        dataContractSerializer.WriteObject(memoryStream, postData);
        var xmlData = Encoding.UTF8.GetString(memoryStream.ToArray(), 0, (int)memoryStream.Length);
        var client = new WebClient();
        client.UploadStringAsync(new Uri(url), "POST", "");
        client.Headers["Content-Type"] = "text/xml";
        client.UploadStringCompleted += (s, ea) =>
        {
            if (ea.Error != null) Console.WriteLine("An error has occured while processing your request");
            var doc = XDocument.Parse(ea.Result);
            if (doc.Root != null) Console.WriteLine(doc.Root.Value);
            if (doc.Root != null && doc.Root.Value.Contains("1"))
            {
                string test = "test";
            }
        };

REST Service method

[WebInvoke(UriTemplate = "TestPost", Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest, RequestFormat = WebMessageFormat.Xml)]
    public string Publish(string market,string sportId, Stream streamdata)
    {
        var reader = new StreamReader(streamdata);
        var res = reader.ReadToEnd();
        reader.Close();
        reader.Dispose();

    }

Don't forget to put the following configuration settings on your REST Service config file if you don't have this it will throw you an error

<system.web>
    <compilation debug="true" targetFramework="4.0" />
    <httpRuntime maxRequestLength="2147000000" maxQueryStringLength="2097151" maxUrlLength="2097151"/>
  </system.web>
  <system.webServer>
    ........
  </system.webServer>
  <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
    <standardEndpoints>
      <webHttpEndpoint>
        <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true" maxReceivedMessageSize="2147000000" maxBufferPoolSize="2147000000" maxBufferSize="2147000000"/>
      </webHttpEndpoint>
    </standardEndpoints>
  </system.serviceModel>

Upvotes: 2

Related Questions