0

I am having trouble uploading files correctly.

We have ios and android app,user select local image file,and uploading to our nginx server.

Summary of my problem: Accidentally,about 5% of the total upload requests ,image files being uploaded ( *.jpg/png/bmp etc.) are received as broken on server side (all zero in hex editors). We found all this broken files are uploaded from IOS 10.3.1.

My Environment: Asp.Net 4.0 Webform + IIS 7 + Nginx.

aspx:

<div class="ui-input-text"><input name="name_4"  accept='image/*'   type="file"  title='⑤please upload your screenshots here' id="id_name_4" ></input></div>

aspx.cs:

private bool SaveAnswers() 
{
    HttpFileCollection files = Request.Files;
    if(files.Count>0&&files.AllKeys.Contains(s))
    {
        string ss = CreateHttpUploadFile("", files[s].InputStream, files[s].FileName, files[s].ContentType, null);
        ...
    }
}

 public  string CreateHttpUploadFile(string url, Stream postedStream, string fileName, string cType, Dictionary<string, string> formDataDic)
 {
      byte[] fileByte = new byte[postedStream.Length];

      // log all image files here
      System.IO.File.AppendAllText
                (Server.MapPath("~/AllImage.txt"),"1");  

      // log broken files here
      if (fileByte.Length>5 && fileByte[0]==0 && fileByte[1] == 0 && fileByte[2] == 0 && fileByte[3] == 0 && fileByte[4] == 0 && fileByte[5] == 0)
      {  
           System.IO.File.AppendAllText 
                  (Server.MapPath("~/COKBrokenImage.txt"),"1");  
      }

      //make a http request to the file server
      ...
 }

Nginx.conf:

upstream website {
    ip_hash;
    server 10.152.9.104:1111;
}

location ~ /elva {
    proxy_pass http://website;
    proxy_redirect default;
    proxy_set_header   Host             $host; 
    proxy_set_header   X-Real-IP        $remote_addr; 
    proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
    proxy_connect_timeout 260;
    proxy_send_timeout 260;
    proxy_read_timeout 260;
   }

Screenshot:Broken file get by server side, open with hex editor

Screenshot: server side count log,5% file broken

chris
  • 80
  • 7
  • The other form data can be obtained correctly except files.Any suggestions would be appreciated. – chris May 04 '17 at 01:55
  • We found this occurs in IOS 10.3.1 uploading image from webview. I suppose it's relative with the newest IOS version. – chris May 04 '17 at 13:05
  • It may be cause by a bug about uiWebView. we will try and update this issue. [http://stackoverflow.com/questions/43411176/apple-file-system-permission-to-read-from-photo-library/43417649#43417649](http://stackoverflow.com/questions/43411176/apple-file-system-permission-to-read-from-photo-library/43417649#43417649) – chris May 05 '17 at 08:43
  • We confirmed,this is caused by a bug in IOS 10.3 with UIWebView, which makes all file input to have the multiple attribute set automatically. Fixed by using WKWebView instead. – chris May 09 '17 at 06:24

1 Answers1

0

We confirmed,this is caused by a bug in IOS 10.3 with UIWebView, which makes all file input to have the multiple attribute set automatically. Fixed by using WKWebView instead.

https://stackoverflow.com/questions/43411176/apple-file-syste‌​m-permission-to-read‌​-from-photo-library/‌​43417649#43417649

Community
  • 1
  • 1
chris
  • 80
  • 7