As we transition to the new Hyland Community, some post links may be temporarily disrupted as we finalize redirects. We apologize for the inconvenience and are working to resolve this as quickly as possible. Details.
… url = "http://$SERVER:$PORT/alfresco/upload/workspace/SpacesStore/$NUUID/$FILENAME?ticket=$TICKET"; … HttpWebResponse response = null; HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest; request.Method = "PUT"; request.SendChunked = true; Stream requestStream = request.GetRequestStream(); CopyStream(contentStream, requestStream); requestStream.Flush(); requestStream.Close(); … //CopyStream body … int bufferSize = Config.Configuration.BUFFER_SIZE, rest = 0; byte[] buffer = new byte[bufferSize]; while ((rest = source.Read(buffer, 0, bufferSize)) > 0) { destination.Write(buffer, 0, rest);//here is the point where Exception occurs!!! destination.Flush(); } …
/// <summary> /// Copies the source to destination stream, iteratively, using an byte[] buffer with customizable length. /// The length of the byte[] is given by Config.Configuration.BUFFER_SIZE. /// IMPORTANT: it dosen't close nor dispose any of the given streams. It just flushes the destination for each successfuly writed byte[]. /// </summary> /// <param name="source">The source stream to copy from</param> /// <param name="destination">The destination stream to copy into</param> /// <returns>true if operation successfully ended</returns> public static bool CopyStream(Stream source, Stream destination) { bool success = true; try { int bufferSize = Config.Configuration.BUFFER_SIZE, rest = 0; byte[] buffer = new byte[bufferSize]; while ((rest = source.Read(buffer, 0, bufferSize)) > 0) { destination.Write(buffer, 0, rest); destination.Flush(); } } catch (Exception e) { //logger.ERR(e); success = false; ; } return success; }
public class Configuration { #region buffer size /// <summary> /// Stores the buffer size used for general stream-bytes operations, to avoid system memory limitation issues /// </summary> private static int _bufferSize = 0; /// <summary> /// accessor for the buffer size. The default value is 1024 if no customized provided (via properties) /// </summary> public static int BUFFER_SIZE { get { if (_bufferSize == 0)//no value set into the properties { _bufferSize = 1024; } return _bufferSize; } } #endregion //buffer size }