locked
ISSUU API - File Size Upload Problem RRS feed

  • Question

  • User-1336361068 posted

    Hi there

    I am trying to utilise the API that issuu.com provide to upload a file to their website.

    If I upload a small pdf file (200Kb) the process works fine. However when I try and upload a larger file (5Mb) I get an error message back from issuu.com that the required field "_uploadFilename" is missing. 

    So I am wondering if my code isn't reading the file correctly/completely for the larger file and therefore I am not sending the required data.

    My code is below for attaching the data and the pdf file to my HTTPWebRequest.

    private static Stream GetPostStream(string fullFilePath, NameValueCollection formData, string boundary)
            {
                Stream postDataStream = new System.IO.MemoryStream();
    
                //adding form data
                string formDataHeaderTemplate = Environment.NewLine + "--" + boundary + Environment.NewLine +
                "Content-Dis-data; name=\"{0}\";" + Environment.NewLine + Environment.NewLine + "{1}";
    
                foreach (string key in formData.Keys)
                {
                    byte[] formItemBytes = System.Text.Encoding.UTF8.GetBytes(string.Format(formDataHeaderTemplate, key, formData[key]));
                    postDataStream.Write(formItemBytes, 0, formItemBytes.Length);
                }
    
                //adding file data
                FileInfo fileInfo = new FileInfo(fullFilePath);
    
                string fileHeaderTemplate = Environment.NewLine + "--" + boundary + Environment.NewLine + "Content-Dis-data; name=\"{0}\"; filename=\"{1}\"" + Environment.NewLine + "Content-Type: application/pdf" + Environment.NewLine + Environment.NewLine;
    
                byte[] fileHeaderBytes = System.Text.Encoding.UTF8.GetBytes(string.Format(fileHeaderTemplate, "file", fileInfo.FullName));
    
                postDataStream.Write(fileHeaderBytes, 0, fileHeaderBytes.Length);
    
                FileStream fileStream = fileInfo.OpenRead();
    
                byte[] buffer = new byte[1024];
    
                int bytesRead = 0;
    
                while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0)
                {
                    postDataStream.Write(buffer, 0, bytesRead);
                }
    
                fileStream.Close();
    
                byte[] endBoundaryBytes = System.Text.Encoding.UTF8.GetBytes("--" + boundary + "--");
                postDataStream.Write(endBoundaryBytes, 0, endBoundaryBytes.Length);
    
    
                return postDataStream;
            }

    Can anyone provide any feedback.

    Thanks

    Nigel

    Monday, November 21, 2011 7:04 PM

All replies

  • User1927273029 posted

    Hello,

    Add this tag to you web.config and specify you sizein maxrequest property

     <httpRuntime maxRequestLength="20480" requestValidationMode="2.0"/>
    
    Tuesday, November 22, 2011 2:05 AM
  • User-1336361068 posted

    Hi jassi_singh

    Thanks for your response.

    I do already have this set in my web.config. Also I have exceutionTimeout="300" on the httpRunTime setting which I trust isn't causing any problems..

    So unfortunately this doesn't solve my mystery.

    Thanks again for your input though.

    Nigel

    Tuesday, November 22, 2011 2:36 AM