This is a migrated thread and some comments may be shown as answers.

zero byte file after upload completes

1 Answer 96 Views
Upload
This is a migrated thread and some comments may be shown as answers.
Ronnie
Top achievements
Rank 1
Ronnie asked on 11 Oct 2011, 04:40 PM

I'm using the silverlight RadUpload control. I have no problems uploading files UNTIL I try to change the name of the uploaded file.

My upload scenario has these 2 requirements:

  1. Save the file outside of the web site directory structure
  2. Ignore the actual filename and save the uploaded file with a new GUID as the filename


Here is my UploadHandler:

    public class BatchUpload : RadUploadHandler

    {

        public override string GetTargetFolder()

        {

            string targetFolder = ConfigurationManager.AppSettings["BatchDataDirectory"];

            return targetFolder;

        }

        public override string GetFileName()

        {

            string filename = GetQueryParameter("sysFilename");

            return filename;

        }

    }



And here is the Silverlight code:

private void RadUpload_FileUploadStarting(object sender, FileUploadStartingEventArgs e)

{

    e.FileParameters["sysFilename"] = (_sysFilename = Guid.NewGuid().ToString());

}



During the upload I can see the file in Windows Explorer and watch the file size increase, but when the upload completes, the file is empty and has a size of zero bytes
.

See: http://youtu.be/-4g2c4xiHKc

1 Answer, 1 is accepted

Sort by
0
Ronnie
Top achievements
Rank 1
answered on 11 Oct 2011, 08:19 PM
Disregard this problem. There was some obscure, old code that was writing an empty string over the file after upload completed. Also, here's a more concise way to rename the file on the server side:

  public override bool SaveChunkData(string filePath, long position, byte[] buffer, int contentLength, out int savedBytes)

        {

            string dir = ConfigurationManager.AppSettings["UploadDir"];

            string filename = GetQueryParameter("NewFilename");

            string newFilepath = Path.Combine(dir, filename);

            return base.SaveChunkData(newFilepath, position, buffer, contentLength, out savedBytes);

        }

Tags
Upload
Asked by
Ronnie
Top achievements
Rank 1
Answers by
Ronnie
Top achievements
Rank 1
Share this question
or