19 ottobre 2010 • ⏲️ 1 min.
Recently I’m moving from swfupload because even if this is a great tool I’m needing to let my users upload larger file.
Server side I’m using ASP.Net so thanks to Alan for this post that helped me on start… but I must edit his code because the final file results were always corrupted because the first bytes of it was as this example lines:
Content-Disposition: form-data; name=“file”; filename=“file.wmv”
This is because Alan reads from Request.InputStream and not from Request.Files that it isn’t empty like he thinks.
My final code that does this is:
int chunk = Request.QueryString[“chunk”] != null ? int.Parse(Request.QueryString[“chunk”]) : 0;
string fileName = Request.QueryString[“name”] != null ? Request.QueryString[“name”] : string.Empty;
HttpPostedFile fileUpload = Request.Files;
using (FileStream fs = new FileStream(Server.MapPath(“/public/” + fileName), chunk == 0 ? FileMode.Create : FileMode.Append))
Byte buffer = new Byte[fileUpload.InputStream.Length];
fileUpload.InputStream.Read(buffer, 0, buffer.Length);
fs.Write(buffer, 0, buffer.Length);
This works great with larger files up to 2GB with Silverlight as runtime: if I try also with a file of 6GB the upload stops to 2GB even if it is segmented by 1MB chunks… and I don’t know why?!
"Man is still the most extraordinary computer of all" (J.F. Kennedy)