No se pudo obtener la respuesta para el archivo grande HTTP put create file usando c #

No se pudo obtener la respuesta para el archivo grande HTTP put create file usando c #

Estoy usando el monitor de servicio del servicio de vigilancia de archivos, cuando el usuario creó el archivo o carpeta que estamos cargando en la nube

Si el tamaño del archivo es superior a 512 MB, se tarda demasiado en obtener la respuesta

aquí estoy confundiendo aquí el problema con mi código o servidor

y la razón de este error

si algún cambio en mi código me sugiere.

{
    var fileFolderObj1 = new FileFolder();
    var postURL = apiBaseUri + "/filefolder/create/file/user/" + userId; // +"?type=file";
    code = HttpStatusCode.OK;
    HttpWebResponse response = null;
    FileInfo f = new FileInfo(filePath);
    long filesizeF = f.Length;

    try
    {
        string selectedFile = null;
        selectedFile = filePath;
        var fi = System.IO.Path.GetFileName(filePath);            

        ////commented for some reason
        var postParameters = new Dictionary<string, object>();
        postParameters.Add("file", new FileParameter(filePath,  ""));
        postParameters.Add("parentId", parentId);
        postParameters.Add("newName", fi);
        postParameters.Add("cloudId", cloudId);
        postParameters.Add("isSecure", isSecure);
        //postParameters.Add("fileSize", fi.Length);
        postParameters.Add("fileSize", filesizeF);

        var userAgent = "Desktop";
        var formDataBoundary = "----WebKitFormBoundary" + DateTime.Now.Ticks.ToString("x");

        var uri = new Uri(postURL);
        var createFileRequest = WebRequest.Create(uri) as HttpWebRequest;
        this.SetBasicAuthHeader(createFileRequest, userId, password);
        createFileRequest.ContentType = "multipart/form-data";
        createFileRequest.Method = "PUT";
        createFileRequest.Timeout =  System.Threading.Timeout.Infinite;
        createFileRequest.KeepAlive = false;/*true;*/
        createFileRequest.UserAgent = userAgent;
        createFileRequest.CookieContainer = new CookieContainer();
        try
        {
            using (var requestStream = createFileRequest.GetRequestStream())
            {        
            }

            using (response = (HttpWebResponse)createFileRequest.GetResponse())
            {
                StreamReader(response.GetResponseStream()).ReadToEnd(); 
                fileFolderObj1 = JsonConvert.DeserializeObject<FileFolder>(reslut);
            }                   
        }
        catch (Exception exc)
        {                    
            if (response != null)
            {
                code = response.StatusCode;
            }
        }               
    }
    catch (Exception exc)
    {                
    }
}       
}

    private static readonly Encoding encoding = Encoding.UTF8;

    private void WriteMultipartFormData(Dictionary<string, object> postParameters, string boundary, Stream requestStream, ILogService logService = null)
    { 
        var needsCLRF = false;
        foreach (var param in postParameters)
        {
            // Skip it on the first parameter, add it to subsequent parameters.
            if (needsCLRF)
            {
                requestStream.Write(encoding.GetBytes("\r\n"), 0, encoding.GetByteCount("\r\n"));
            }
            needsCLRF = true;
            if (param.Value is FileParameter)
            {
                var fileToUpload = (FileParameter)param.Value;
                // Add just the first part of this param, since we will write the file data directly to the Stream
                var header = string.Format("--{0}\r\nContent-Disposition: form-data; name=\"{1}\"; filename=\"{2}\"\r\nContent-Type: {3}\r\n\r\n",
                    boundary,
                    param.Key,
                    fileToUpload.FileName ?? param.Key,
                    fileToUpload.ContentType ?? "application/octet-stream");

                requestStream.Write(encoding.GetBytes(header), 0, encoding.GetByteCount(header));
                // Write the file data directly to the Stream, rather than serializing it to a string.
                FileStream fileStream = new FileStream(fileToUpload.FileName, FileMode.Open, FileAccess.Read);

                byte[] buffer = new byte[4096];

                int bytesRead = 0;
                while ((bytesRead = fileStream.Read(buffer, 0,buffer.Length)) != 0)
                {
                    requestStream.Write(buffer, 0, bytesRead);
                    logService.Debug("WRITEMULTIPART FORM DATA Bufferlent Running :{0}", bytesRead);
                }
                fileStream.Close();


            }
            else
            {
                var postData = string.Format("--{0}\r\nContent-Disposition: form-data; name=\"{1}\"\r\n\r\n{2}",
                    boundary,
                    param.Key,
                    param.Value);
                requestStream.Write(encoding.GetBytes(postData), 0, encoding.GetByteCount(postData));
            }
        }

        // Add the end of the request.  Start with a newline
        var footer = "\r\n--" + boundary + "--\r\n";

        requestStream.Write(encoding.GetBytes(footer), 0, encoding.GetByteCount(footer));

    }
}

Respuestas a la pregunta(0)

Su respuesta a la pregunta