mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Merged V3.4 to HEAD
24791: Fixed ALF-6560: MIME type not detected (set to application/octet-stream) when content written via FileFolderService git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@24886 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -1133,7 +1133,17 @@ public class FileFolderServiceImpl implements FileFolderService
|
|||||||
{
|
{
|
||||||
throw new InvalidTypeException("Unable to get a content writer for a folder: " + fileInfo);
|
throw new InvalidTypeException("Unable to get a content writer for a folder: " + fileInfo);
|
||||||
}
|
}
|
||||||
return contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
|
final ContentWriter writer = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
|
||||||
|
// Ensure that a mimetype is set based on the filename (ALF-6560)
|
||||||
|
// This has been removed from the create code in 3.4 to prevent insert-update behaviour
|
||||||
|
// of the ContentData.
|
||||||
|
if (writer.getMimetype() == null)
|
||||||
|
{
|
||||||
|
final String name = fileInfo.getName();
|
||||||
|
writer.setMimetype(mimetypeService.guessMimetype(name));
|
||||||
|
}
|
||||||
|
// Done
|
||||||
|
return writer;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getExtension(String name)
|
private String getExtension(String name)
|
||||||
|
@@ -32,6 +32,7 @@ import junit.framework.TestCase;
|
|||||||
import org.alfresco.error.AlfrescoRuntimeException;
|
import org.alfresco.error.AlfrescoRuntimeException;
|
||||||
import org.springframework.extensions.surf.util.I18NUtil;
|
import org.springframework.extensions.surf.util.I18NUtil;
|
||||||
import org.alfresco.model.ContentModel;
|
import org.alfresco.model.ContentModel;
|
||||||
|
import org.alfresco.repo.content.MimetypeMap;
|
||||||
import org.alfresco.repo.dictionary.DictionaryDAO;
|
import org.alfresco.repo.dictionary.DictionaryDAO;
|
||||||
import org.alfresco.repo.dictionary.M2Model;
|
import org.alfresco.repo.dictionary.M2Model;
|
||||||
import org.alfresco.repo.dictionary.M2Type;
|
import org.alfresco.repo.dictionary.M2Type;
|
||||||
@@ -731,4 +732,16 @@ public class FileFolderServiceImplTest extends TestCase
|
|||||||
// Expected
|
// Expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testAlf6560MimetypeSetting() throws Exception
|
||||||
|
{
|
||||||
|
FileInfo fileInfo = fileFolderService.create(workingRootNodeRef, "Something.html", ContentModel.TYPE_CONTENT);
|
||||||
|
NodeRef fileNodeRef = fileInfo.getNodeRef();
|
||||||
|
// Write the content but without setting the mimetype
|
||||||
|
ContentWriter writer = fileFolderService.getWriter(fileNodeRef);
|
||||||
|
writer.putContent("CONTENT");
|
||||||
|
|
||||||
|
ContentReader reader = fileFolderService.getReader(fileNodeRef);
|
||||||
|
assertEquals("Mimetype was not automatically set", MimetypeMap.MIMETYPE_HTML, reader.getMimetype());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user