diff --git a/chrome/content/zotero/xpcom/attachments.js b/chrome/content/zotero/xpcom/attachments.js index 0e10a7465..b5909b609 100644 --- a/chrome/content/zotero/xpcom/attachments.js +++ b/chrome/content/zotero/xpcom/attachments.js @@ -82,14 +82,15 @@ Zotero.Attachments = new function(){ // Create directory for attachment files within storage directory var destDir = this.createDirectoryForItem(itemID); - file.copyTo(destDir, newName); // Point to copied file var newFile = destDir.clone(); newFile.append(newName); - var mimeType = Zotero.MIME.getMIMETypeFromFile(newFile); + // Copy file to unique filename, which automatically shortens long filenames + newFile = Zotero.File.copyToUnique(file, newFile); + var mimeType = Zotero.MIME.getMIMETypeFromFile(newFile); attachmentItem.attachmentMIMEType = mimeType; attachmentItem.attachmentPath = this.getPath(newFile, this.LINK_MODE_IMPORTED_FILE); diff --git a/chrome/content/zotero/xpcom/file.js b/chrome/content/zotero/xpcom/file.js index 7383d4572..3e98deef5 100644 --- a/chrome/content/zotero/xpcom/file.js +++ b/chrome/content/zotero/xpcom/file.js @@ -39,7 +39,6 @@ Zotero.File = new function(){ this.putContents = putContents; this.getValidFileName = getValidFileName; this.truncateFileName = truncateFileName; - this.copyToUnique = this.copyToUnique; this.getCharsetFromFile = getCharsetFromFile; this.addCharsetListener = addCharsetListener; @@ -287,14 +286,14 @@ Zotero.File = new function(){ } - function copyToUnique(file, newFile) { + this.copyToUnique = function (file, newFile) { newFile.createUnique(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0644); var newName = newFile.leafName; newFile.remove(null); // Copy file to unique name file.copyTo(newFile.parent, newName); - return file; + return newFile; }