ShareFile-NET
ShareFile-NET copied to clipboard
Uploaded file names are truncated before colons instead of throwing an illegal character exception
When uploading a file, the FileName field in an UploadSpecificationRequest cannot contain colon characters, likely since it is a reserved character on Windows and Linux systems. If any are present, then the file name is quietly truncated to only be the remaining input string after the last colon, instead of throwing a System.ArgumentException.
Example code snippet:
UploadSpecificationRequest uploadRequest = new UploadSpecificationRequest() { FileName = fileName, FileSize = contentStream.Length, Parent = destinationFolder.url };
await client.GetAsyncFileUploader(uploadRequest, contentStream).UploadAsync();
- Setting
string fileName = "postmanTest_2020-02-24T09.51.51-05.00.txt"for the above example code functions as expected. - Setting
string fileName = "postmanTest_2020-02-24T09:51:51-05:00.txt"will cause the example code to create a file named "00.txt". - Setting
string fileName = "NoneOfThisWillBeIncluded:OnlyThisPartWillBeIncluded.txt"will cause the example code to create a file named "OnlyThisPartWillBeIncluded.txt".
An example of expected behavior can be found in System.IO.File.Create(string path), which throws a System.ArgumentException with the message "Illegal characters in path."
I see where you are coming from; it is definitely a weird behavior, but given how long we've operated with that behavior, we probably wouldn't be able to change it without breaking something that depends on it.
Probably your best course of action would be to check for bad chars in your code prior to calling the Upload function.
That is the workaround that I implemented back in February. But I would be surprised if something depended on strings being truncated from the left when certain characters are included.