Does this TTL start as soon as the file starts uploading? Or when the upload is finished?
Thanks
9 Answers, 1 is accepted
This property controls how long temporary files should be kept before application automatically deleting them. When you are using custom AsyncUploadConfiguration, TemporaryFileExpiration 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.
Hristo Valyavicharski
Telerik
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.
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
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?
Do I actually need to rename the temp file? Right now I am renaming File.GetName()....
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
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?
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...