There are some pitfalls in the upload and set references pipeline that you should watch out for.
When dealing with file uploads and set references, the file name will sometimes corrupt your upload if it contains space or other special characters. It's best to URL encode the file name.
When you set references between files, you can swap out different versions of a child file, set the reference, go through the translation again, and the new version will show up in the viewer. If you still want to keep the older version, though, uploading a new file with the same name will overwrite the old file. That
Two things you can do to counter these two scenarios
1. URL encode the file.
2. Date stamp your upload, so each of your upload has a unique name.
Here's some sample code written in JavaScript for reference:
/**
* @param {string} fileName a file name with extension
* @return {string} url encoded file name with date and extension
*/
function encodeFileName(fileName) {
if (typeof fileName !== "string") {
return null;
}
var fileExtensionIndex = fileName.lastIndexOf(".");
if (fileExtensionIndex < 0) {
fileExtensionIndex = fileName.length;
}
var fileExtension = fileName.substring(fileExtensionIndex, fileName.length);
var fileName = fileName.substring(0, fileExtensionIndex);
fileName = encodeURIComponent(fileName) + Date.now() + fileExtension;
return fileName;
}
/**
* @param {string} file name encoded using encodeFileName
* @return {string} orignial file name
*/
function decodeFileName(fileName) {
if (typeof fileName !== "string") {
return null;
}
var fileExtensionIndex = fileName.lastIndexOf(".");
if (fileExtensionIndex < 0) {
fileExtensionIndex = fileName.length;
}
var fileExtension = fileName.substring(fileExtensionIndex, fileName.length);
fileName = fileName.substring(0, fileExtensionIndex - 13);
fileName = decodeURIComponent(fileName) + fileExtension;
return fileName;
}
Copy the code into your JavaScript console and try it out!
Now, if I have a file name that says "平面图 $∂.dwg"
, after the encoding the name will be "%E5%B9%B3%E9%9D%A2%E5%9B%BE%20%24%E2%88%821442527104059.dwg"
. Much more URL-friendly!
Notice how the .dwg extension is still there. This is how the translation service determines which pipeline it should go through, be it AutoCAD, Revit, Navisworks, etc.
Comments
You can follow this conversation by subscribing to the comment feed for this post.