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