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

What exactly does the TimeToLive property on the AsyncUploadConfiguration control?

9 Answers 133 Views
AsyncUpload
This is a migrated thread and some comments may be shown as answers.
Richard
Top achievements
Rank 1
Richard asked on 25 Jul 2013, 08:34 PM
How is this different from the TTL property of the Radasyncupload control? I noticed that if the TTL is zeroed out when using a custom upload handler / custom config, The file upload is corrupted due to the temp file being deleted part way through the upload it seems. If I correctly give it a time of say 5 minutes , everything is fine. Even though the RadAsyncupload control already has a TTL set it is not honored if I used the custom config.

Does this TTL start as soon as the file starts uploading? Or when the upload is finished?

Thanks

9 Answers, 1 is accepted

Sort by
0
Hristo Valyavicharski
Telerik team
answered on 30 Jul 2013, 01:49 PM
Hi Richard,

This property controls how long temporary files should be kept before application automatically deleting them. When you are using custom AsyncUploadConfigurationTemporaryFileExpiration property reads value from TimeToLive property.

After the Default Upload Configuration is created TTL is send to the client together with all properties from AsyncUploadConfiguration. Then the user selects file for uploading and the configuration is transferred from the client to the upload handler. The TTL starts right after the file is uploaded.

Regards,
Hristo Valyavicharski
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Allen
Top achievements
Rank 2
Iron
Veteran
answered on 27 Jul 2020, 09:54 AM

At the risk of dragging up an ancient topic from the bottom of the sea, does this reply mean that a custom config MUST set a TTL or it will potentially cause issues as described in the original post?  How could a reasonable value be estimated?  What exactly occurs if the TTL expires in the middle of an upload (in other words, is there an exception that can be trapped?).

If a file has a TTL, is the web app ALWAYS going to delete it automatically or will it fail to do so if the application terminates or is restarted?

 

Thank you.

0
Allen
Top achievements
Rank 2
Iron
Veteran
answered on 27 Jul 2020, 09:55 AM
And as a corollary to this, since I am using file.SaveAs(newName, true) in my handler, I can just ignore the temp files accumulating in the staging folder? Thank you.
0
Peter Milchev
Telerik team
answered on 27 Jul 2020, 12:38 PM

Hello Allen,

The TimeToLive property of the configuration is actually the equivalent of the TemporaryFileExpiration property of the AsyncUpload and is used when adding the cache dependency of the temp file:

context.Cache.Insert(tempFileName, fullPath, null, DateTime.Now.Add(timeToLive), TimeSpan.Zero, CacheItemPriority.NotRemovable, RemovedCallback);

Also, the default implementation of file.SaveAs is as below, so the temporary file should disappear as soon as you call file.SaveAs:

 public override void SaveAs(string fileName, bool overwrite)
        {
            if (overwrite && File.Exists(fileName))
            {
                File.Delete(fileName);
            }

            File.Move(TempFilePath, fileName);
        }

Regards,
Peter Milchev
Progress Telerik

0
Allen
Top achievements
Rank 2
Iron
Veteran
answered on 27 Jul 2020, 03:01 PM

Hi Peter.  I rename the files in the handler to suit the application requirements (for example, add some metadata to the end of the name).  So file XYZ.pdf becomes file XYZ-elaborated-with-metadata.pdf.  This occurs in a call to ChangeOriginalFileName that overrides the base class.  Then I do SaveAs.  Unfortunately, it appears that at that point the temp file is still named 

XYZ.pdf.tmp and it gets left behind.  

I am sure you are sick of hearing from me about this.... but that is what I am seeing.  Do I need to override SaveAs also?

 

 

0
Allen
Top achievements
Rank 2
Iron
Veteran
answered on 27 Jul 2020, 03:02 PM

Do I actually need to rename the temp file?  Right now I am renaming File.GetName()....

 

0
Peter Milchev
Telerik team
answered on 28 Jul 2020, 11:42 AM

Hello Allen,

The ChangeOriginalFileName is just changing the original filename, not the file name of the temporary file.

protected internal virtual string ChangeOriginalFileName(string fileName)
{
    return fileName;
}

 internal void HandleChunkUploadRequest(string serializedMetaData)
        {
            var metaData = (ChunkMetaData)SerializationService.Deserialize(serializedMetaData, typeof(ChunkMetaData));

            if (CheckFileNameForInvalidChars(metaData.UploadID))
                throw new Exception("The uploaded file name contains invalid characters!");

            RequestData.UploadedFile.FileName = ChangeOriginalFileName(RequestData.UploadedFile.FileName);

            if (CheckOriginalFileNameForInvalidChars(RequestData.UploadedFile.GetName()))
                throw new Exception("The uploaded file name contains invalid characters!");

 private void ProcessUploadedFile()
        {
            if (!ValidateSize(RequestData.UploadedFile.ContentLength, Configuration.MaxFileSize))
                return;

            RequestData.UploadedFile.FileName = ChangeOriginalFileName(RequestData.UploadedFile.FileName);

            if (!ValidateFileExtension(RequestData.UploadedFile.GetExtension()))
                return;

            if (CheckFileNameForInvalidChars(TemporaryFileName))
                throw new Exception("The uploaded file name contains invalid characters!");

            if (CheckOriginalFileNameForInvalidChars(RequestData.UploadedFile.GetName()))
                throw new Exception("The uploaded file name contains invalid characters!");

            var fileInfo = Process(RequestData.UploadedFile, Context, Configuration, TemporaryFileName);

 

The TemporaryFileName of the AsyncUploadHandler is declared as below:

private string temporaryFileName;
        /// <summary>
        /// Gets or sets the name of the temporary file.
        /// </summary>
        /// <value>The name of the temporary file.</value>
        public string TemporaryFileName
        {
            get
            {
                if (string.IsNullOrEmpty(temporaryFileName))
                {
                    temporaryFileName = Path.GetRandomFileName() + Temp_Files_Extension;
                }

                return temporaryFileName;
            }
            set
            {
                temporaryFileName = value;
            }
        }

With that said, if you need to override the name of the file in the destination, you just need to pass the new name in the SaveAs method, without overriding the original name in the handler.

Regards,
Peter Milchev
Progress Telerik

0
Allen
Top achievements
Rank 2
Iron
Veteran
answered on 28 Jul 2020, 12:16 PM

Up until the last line of your kind reply, I was with you.  Then you state "you just need to pass the new name in the SaveAs method, without overriding the original name in the handler."  - OK,so does that mean that when I want to use a new name i.e. redirect the file to a configured target directory and adorn the name as I see fit, I should NOT use ChangeOriginalFileName, but a custom method that does not override?  This apparently conflicts with the documentation snippet (somewhere in the soup ) that says it should be overridden.

So, in sum:

In the handler Process

a) grab the file name

b) rename it with a custom method, not an override of ChangeOriginalFileName

c) SaveAs with the beautiful new name

d) Use that name everywhere, and never use the original file name for anything thereafter in the hander or the result object or the page itself?

 

     

 

 

 

 

 

 

0
Allen
Top achievements
Rank 2
Iron
Veteran
answered on 28 Jul 2020, 01:06 PM

And on further review, whether the name is changed or not with ChangeOriginalFileName  it makes no difference.  Files go where expected and the temp files are now magically disappearing also as expected.  Problem resolved AFAICT...

 

Tags
AsyncUpload
Asked by
Richard
Top achievements
Rank 1
Answers by
Hristo Valyavicharski
Telerik team
Allen
Top achievements
Rank 2
Iron
Veteran
Peter Milchev
Telerik team
Share this question
or