In Alfresco users can use rules to move files. How do I programmatically move a file from one folder to another?
Do you have an example?
I am using Alfresco 7.0 Share/Community version
Using Script :
var backupFolder = space.childByNamePath('testfolder');
if (backupFolder == null)
{
backupFolder = space.createFolder('testfolder');
}
document.move(backupFolder );
Ref : https://hub.alfresco.com/t5/alfresco-content-services-hub/javascript-api-cookbook/ba-p/293260
https://docs.alfresco.com/content-services/6.1/develop/reference/repo-root-objects-ref/
Related
I have upgraded my project from .net framework to .net 6 (core). In my project, there are many places where Bitmap is used. I have read in the microsoft documentations that System.Drawing.Common will only support the Windows platform and even after adding the EnableUnixSupport configuration, it will not be supported in net7.So, now I am using ImageSharp.Web. I have the scenario where I save a file as Image (the format is .tiff) then I read from that path as bitmap and save as PNG ( due to some business rule)
Following is the line of code I am trying change:
Bitmap.FromFile(completePath).Save(pngPath, ImageFormat.Png);
This is the code I have converted into. The only issue is how to save as a new file name as the Tiff file has tiff in the file name.
string extension = _GetExtension(img.ContentType);
if (extension == Constants.TiffExtension)
{
fileName = fileName.Replace(Constants.TiffExtension, "PNG");
using (var outputStream = new FileStream(completePath, FileMode.CreateNew))
{
var image = SixLabors.ImageSharp.Image.Load(completePath);
image.SaveAsync(outputStream, new PngEncoder()); //how to save new file name?
}
}
You can use the image.Save(fileName); overload to save a image to a file. The file name overload that takes just a path will automatically choose the correct encoder based on the file extension.
I was using the ImageSharp.Web package while the one I needed was the basic ImageSharp package. Special thanks to #James South for correcting me and #tocsoft for the guidance.
I have fixed it by the following code which is working:
if (extension == Constants.Conversion.TiffExtension)
{
using (SixLabors.ImageSharp.Image image = SixLabors.ImageSharp.Image.Load(completePath))
{
string pngPath = completePath.Replace(Constants.Conversion.TiffExtension, Conversion.DefaultExtension);
image.Save(pngPath);
fileName = fileName.Replace(Constants.Conversion.TiffExtension, Conversion.DefaultExtension);
}
}
I am using the CachedImage component of ffimageloading. I have a kind of gallery with a carousel view.
All the images are loaded through an internet URL, they are not local images. I would like to add the image sharing function. But I don't want to download the file again, I would like to know if there is a way to access the file that the CachedImage component already downloaded to be able to reuse it in the share function.
try using MD5Helper
var path = ImageService.Instance.Config.MD5Helper.MD5("https://yourfileUrlOrKey")'
Thanks Jason
I share with you how part of my code is:
var key = ImageService.Instance.Config.MD5Helper.MD5("https://yourfileUrlOrKey");
var imagePath = await ImageService.Instance.Config.DiskCache.GetFilePathAsync(key);
var tempFile = Path.Combine(Path.GetTempPath(), "test.jpg");
if (File.Exists(tempFile))
{
File.Delete(tempFile);
}
File.Copy(imagePath, tempFile);
await Share.RequestAsync(new ShareFileRequest
{
Title = "Test",
File = new ShareFile(tempFile)
});
The temporary file I believe, since the cached file has no extension and the applications do not recognize the type.
I had posting in alfresco hub , couldnt get solution yet.
I was trying to convert javascript API code to java API which move files to different content store(' storeB'). We have storeB defined in - 'content-store-selector-context.xml'. We are using Enterrprises version of Alfresco 5.2.
java script code as follows , - Works perfectly fine . its working code.
for each (var n in node.children) {
if (n.isDocument) {
//Apply script for moving files to DMS Store 01
n.removeAspect("cm:versionable");
n.addAspect("cm:storeSelector");
n.properties['cm:storeName'] = "storeB";
n.save();
}
}
Below is Java API Code - But this code is not moving files to 'storeB'. Is there anything i am missing ?
Is there any similiar method available in java APIs.
List<ChildAssociationRef> children = nodeService.getChildAssocs(dayFolderRef);
Map<QName, Serializable> aspectsProps = new HashMap<QName, Serializable>(1);
aspectsProps.put(ContentModel.PROP_STORE_NAME, "storeB");
LOG.info("Folder::" + dayFolderRef.getId());
LOG.info("Number of Subfolder to be moved is ::" + children.size());
for (ChildAssociationRef childAssoc : children) {
NodeRef childNodeRef = childAssoc.getChildRef();
if (ContentModel.TYPE_CONTENT.equals(nodeService.getType(childNodeRef))) {
LOG.info("Moving the file to secondary storae "+childNodeRef.getId());
nodeService.removeAspect(childNodeRef, ContentModel.ASPECT_VERSIONABLE);
nodeService.addAspect(childNodeRef, ContentModel.ASPECT_STORE_SELECTOR, aspectsProps);
}
}
I can see a save method is java script API. based on response recieved Alfresco forum , there is no save method in javascript API. Java API run in transactions , so will commit eventually . But i can see from DB using the below SQL -
SELECT count(*)
FROM alf_content_url
WHERE orphan_time IS NOT NULL;
the above SQL returns same count after executing the code , so no DB updates happening. Anything wrong ?
Any help , appreciated
Regards
Brijesh
I don't see why that would not work, are you positive you're even entering that method? Try adding the content store selector aspect with no properties map, then add the content store name property with setProperty method separately.
I want a sub folder within Document library as rootNode in Alfresco Shave 4.2
For Example In Document Library the folder path is Documents > XYZ > User1. When user accesses Document Library by default the content in Documents > XYZ > User1 should be displayed instead of content in Document. If we customize rootNode property from below code which is part of toobar.get.js it should work..I replaced rootNode with XYZ and it works. But rootNode="XYZ/User1" does not work
Not sure how to speciy the sub folder ?
var docListToolbar = {
id: "DocListToolbar",
name: "Alfresco.DocListToolbar",
options: {
siteId: (page.url.templateArgs.site != null) ? page.url.templateArgs.site :"",
rootNode: toolbar.rootNode != null ? toolbar.rootNode : "",
hideNavBar: Boolean(toolbar.preferences.hideNavBar),
googleDocsEnabled: toolbar.googleDocsEnabled,
repositoryBrowsing: toolbar.rootNode != null,
useTitle: (useTitle == "true"),
syncMode: toolbar.syncMode != null ? toolbar.syncMode : "",
createContentByTemplateEnabled: model.createContentByTemplateEnabled,
createContentActions: model.createContent
}
};
model.widgets = [docListToolbar];
since edit online is not present in My Files we created a cutom site in Alfreso Share as a custom My Files section.
Maybe it's a bit late but I would suggest to create a custom site page, almost the same as document library, but with changed root node. And then you can easily replace Document Library page with custom one in site settings.
I have a quite nice example here: http://streetturtle.ninja/jekyll/update/2014/10/23/alf-custom-doclibrary-site-page/. It is almost the same as you want, but the root node changes according to the logged user.
I have created an Asp.net application.
It contains a folder called PDF and a folder called Requirement just beneath that.
I have a link in another page called Requirement.
If i click on that link i need to find all the files in the folder PDF/Requirement.
var getFileName = Directory.GetFiles(Server.MapPath("~/PDF/Requirement")); // Collection Of file name with extention.
var getFileNameExcludeSomeExtension1 = from f in Directory.GetFiles(Server.MapPath("~/PDF/Requirement"))
where Path.GetExtension(f) != ".scc" && Path.GetExtension(f) != ".db"
select Path.GetFileNameWithoutExtension(f); // Collection Of file name with extention and filtering.
var getFileNameExcludeSomeExtension2 = from f in Directory.GetFiles(Server.MapPath("~/PDF/Requirement"))
where Path.GetExtension(f) != ".scc" && Path.GetExtension(f) != ".db"
select Path.GetFileName(f); // Collection Of file name with out extention and filtering.
I suggest to use EnumerateFiles as this Regex to find a file in folder and if you tried GetFiles dont because of performance you could see difference in this What is the difference between Directory.EnumerateFiles vs Directory.GetFiles?