Mode of publishing - static
I'm trying to publish images, but the issue is whenever I publish those images, their TCM URI is appended to their name (i.e if image name is example and its TCM URI is like tcm:1-115, image filename becomes example_tcm1-115).
I have written the following code:
public void Transform(Engine engine, Package package)
{
Filter MMCompFilter = new Filter();
MMCompFilter.Conditions["ItemType"] = Tridion.ContentManager.ItemType.Component;
Folder folder = engine.GetObject("tcm:1-1-2") as Folder;
foreach (Component MMcomp in folder.GetItems(MMCompFilter))
{
Binary binary = engine.PublishingContext.RenderedItem.AddBinary(MMcomp);
String binaryurl = binary.Url;
char[] array = binaryurl.ToCharArray();
Array.Reverse(array);
string obj = new string(array);
string final = newImagepath(obj);
char[] array2 = final.ToCharArray();
Array.Reverse(array2);
string obj2 = new string(array2);
package.PushItem("Image", package.CreateHtmlItem(obj2));
}
public string newImagepath(string filePath)
{
int formatIndex =filePath.IndexOf(".");
string format= filePath.Substring(0,formatIndex);
int finalPath=filePath.IndexOf("_");
string newPath=filePath.Substring((finalPath+1));
return (format+"."+newPath);
}
}
I want to publish images without the TCM URI appended to it. Plz suggest how can it be done.
Chris Summers wrote a very nice article on this very topic http://www.urbancherry.net/blogengine/post/2010/02/09/Unique-binary-filenames-for-SDL-Tridion-Multimedia-Components.aspx
It is basically a very simple thing to fix, but can have huge consequences which you should be aware of!
You can only publish a binary with a certain file-name in a single location once (and a binary can only be published to a single location on the presentation server, unless you publish it as a variant). However, in the CMS it is very easy to create Multimedia Components with the same binary file-name in different folders, which if they get published to the same location will be in conflict. That is why by default SDL Tridion appends the TCM URI to the filename to make it unique.
Simplest is always best.
In your TBB, just push the individual images to the package:
package.PushItem(package.CreateMultimediaItem(component.Id));
Then use the "PublishBinariesInPackage" TBB to publish these images to your presentation server.
You can use the RenderedItem.AddBinary method for this goal. Some of the overloaded versions of the method allows to publish an image as a stream, and pass any file name. For example:
public Binary AddBinary(
Stream content,
string filename,
string variantId,
string mimeType
)
Related
I am creating an app where
user can upload the text file and then
find most used word and change that word in text and
show the changed text to the user.
if it is possible, I would like to
get the file’s text content before uploading when Post method is being called and save that content
so I add the “DownloadTextAsync()” method inside of the POST method, but it seems like I am calling this method to the wrong subject?
[HttpPost("UploadText")]
public async Task<IActionResult> Post(List<IFormFile> files)
{
string connectionString = Environment.GetEnvironmentVariable("mykeystringhere");
// Create a BlobServiceClient object which will be used to create a container client
BlobServiceClient blobServiceClient = new BlobServiceClient(connectionString);
//Create a unique name for the container
string containerName = "textdata" + Guid.NewGuid().ToString();
// Create the container and return a container client object
BlobContainerClient containerClient = await blobServiceClient.CreateBlobContainerAsync(containerName);
// Create a local file in the ./data/ directory for uploading and downloading
string localPath = "./data/";
string fileName = "textfiledata" + Guid.NewGuid().ToString() + ".txt";
string localFilePath = Path.Combine(localPath, fileName);
// Get a reference to a blob
BlobClient blobClient = containerClient.GetBlobClient(fileName);
// Open the file and upload its data
using FileStream uploadFileStream = System.IO.File.OpenRead(localFilePath);
await blobClient.UploadAsync(uploadFileStream, true);
uploadFileStream.Close();
string downloadFilePath = localFilePath.Replace(".txt", "DOWNLOAD.txt");
// Get the blob file as text
string contents = blobClient.DownloadTextAsync().Result;
//return the string
return contents;
//if (uploadSuccess)
// return View("UploadSuccess");
//else
// return View("UploadError");
}
The issues I am having are
I understood that ‘blobClient’ is the reference to the blob, where I can get the file’s data but this must be wrong?
Also it seems like I cannot use “CloudBlobContainer” nor the “CloudBlockBlob blob”. Is it because inside of the POST method, the blob has been just initialized and does not exist when these twos are executed?
Also when I test the POST method, the console throws “Refused to load the font '' because it violates the following Content Security Policy directive: "default-src 'none'". Note that 'font-src' was not explicitly set, so 'default-src' is used as a fallback.” which I googled but have no idea what it means?
I have tried different ways but keep getting CANNOT POST/“ But could not really find the solid anwers. Could this be related to my POST method?
I understood that ‘blobClient’ is the reference to the blob, where I
can get the file’s data but this must be wrong?
That's correct in a sense that you can use blobClient to perform operations on blob like upload/download etc. I am not sure why you say but this must be wrong.
Also it seems like I cannot use “CloudBlobContainer” nor the
“CloudBlockBlob blob”. Is it because inside of the POST method, the
blob has been just initialized and does not exist when these twos are
executed?
No, this is happening because you're using a newer version of SDK (version 12.x.x) and CloudBlobContainer and CloudBlockBlob are available in the older version of the SDK.
Also when I test the POST method, the console throws “Refused to load
the font '' because it violates the following Content Security Policy
directive: "default-src 'none'". Note that 'font-src' was not
explicitly set, so 'default-src' is used as a fallback.” which I
googled but have no idea what it means? I have tried different ways
but keep getting CANNOT POST/“ But could not really find the solid
anwers. Could this be related to my POST method?
Not sure why this is happening. You may want to ask a separate question for this and when you do, please include the HTML portion of your code as well.
I am trying to program a MODULE for the Ignition SDK but I am running into problems with the paths of the strings in the .properties file not working properly.
I have a file called
ProfileSettings.properties
and one called
ProfileSettings.java
In .properties file, I have the following strings:
Category.Settings=Connection
ConnectionString.Name=Connection String
ConnectionString.Desc=Connection String for the IoT Hub device
MaxTime.Name=Maximum time
MaxTime.Desc=The time spent
MaxMessages.Name=Maximum to collect
MaxMessages.Desc=will be collected
and in the .java file, I have reference to the strings by using
public static final StringField connectionString = new StringField(META, "ConnectionString");
public static final IntField maxTime = new IntField(META, "MaxTime");
public static final IntField maxMessages = new IntField(META, "MaxMessages");
Category CONNECTION_CATEGORY = new Category("ProfileSettings.Category.Connection", 1001)
.include(connectionString, maxTime, maxMessages);
but when I load the module into the gateway and look at the configuration page, I get ¿ProfileSettings.ConnectionString.Name? where it shows question marks
around the path and not the actual text needed for all the strings
Maybe try using the complete field names?
public static final StringField connectionString = new StringField(META, "ConnectionString.Name");
Or possibly
public static final StringField connectionStringName = new StringField(META, "ConnectionString.Name");
It would be helpful to have more information about what and where those files are from. Is the .properties file or properties.java something you wrote or is that something that comes as part of the SDK?
I'm trying to run a ScanContent processor on Apache Nifi, and whilst I can get the processor to run when scanning a text file, and using a .txt dictionary file with the search terms contained in it (and delimited by a newline character), I cannot get it to run when searching a file using the binary type of the processor for the dictionary file.
I am unsure whether I am simply using the wrong format for the binary dictionary file, or whether it needs to be encoded differently. I couldnt find any example dictionaries anywhere online that would be of any use (most things were related to the ScanAttributes instead).
The format of my dictionary file is:
(inside a .txt file)
32 00001001001000010000100001000000\n
The requirements according to the documentation are that the dictionary terms need to be a 4 byte integer, followed by the binary search term.
Does anyone have any experience of using this processor with a binary dictionary that might be able to help specify the format?
A binary dictionary file would typically be generated as the output of another program. There is an example in the ScanContent unit tests for how to accomplish this in Java:
#Test
public void testBinaryScan() throws IOException {
// Create dictionary file.
final String[] terms = new String[]{"hello", "good-bye"};
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (final DataOutputStream dictionaryOut = new DataOutputStream(baos);) {
for (final String term : terms) {
final byte[] termBytes = term.getBytes("UTF-8");
dictionaryOut.writeInt(termBytes.length);
dictionaryOut.write(termBytes);
}
final byte[] termBytes = baos.toByteArray();
final Path dictionaryPath = Paths.get("target/dictionary");
Files.write(dictionaryPath, termBytes, StandardOpenOption.CREATE, StandardOpenOption.WRITE);
...
I have an Alfresco 4.2 document at /Sites/swsdp/documentLibrary/Presentations/test1.txt with id workspace://SpacesStore/626216a1-5f9e-4010-a424-e2e0ec4f2663;1.0.
Here is my DotCMIS code to deal with a ChangeLog change event:
ICmisObject cmisObject = session.GetObject(
"workspace://SpacesStore/626216a1-5f9e-4010-a424-e2e0ec4f2663;1.0");
if (null != (document = cmisObject as IDocument))
{
String filename = document.ContentStreamFilename; // returns: "test1.txt"
List<String> paths = document.Paths; // returns: Empty list
}
Why is paths an empty list?
Why does it not contain /Sites/swsdp/documentLibrary/Presentations/test1.txt?
I know it is not exactly the same, but OpenCMIS documentation says this for the same method:
Returns the list of paths of this object or an empty list if this object is unfiled or if this object is the root folder
The problem is that I was using the old CMIS URL of Alfresco.
It is solved by using the new URL format:
http://<host>/alfresco/api/-default-/public/cmis/versions/1.0/atom
This isn't an answer but I can't add a comment since my rep is too low.
It works for me. I got a document's path using an Alfresco 4.2 system
btw, your code should be
String filename = document.ContentStreamFileName; //camel case
IList<String> paths = document.Paths; //IList vs List
I am using ISAPI rewrite on a project and would like to know if it is possible to publish a .htaccess file from Tridion?
I have tried creating a Page Template with the .htaccess extension but can't create a page with no name.
Any ideas?
Could I use a C# TBB to change the page name?
I would also choose to use a binary to achieve this, but if you want to manage the htaccess file using text, rather than as a multimedia component, you can push a binary into your package using the following technique:
1) Push the text of the Htaccess file into the package with an accessible name (i.e. Binary_Text)
2) Use code similar to the following to create a text file from the text in the variable and add it to the package
class publishStringItemAsBinary : ITemplate
{
public void Transform(Engine engine, Package package)
{
TemplatingLogger log = TemplatingLogger.GetLogger(typeof(publishStringItemAsBinary));
TemplateUtilities utils = new TemplateUtilities();
System.IO.Stream inputStream = null;
try
{
string strInputName = package.GetValue("InputItem");
string strFileName = package.GetValue("strFileName");
string sg_Destination = package.GetValue("sg_Destination");
string itemComponent = package.GetValue("mm_Component");
inputStream = new MemoryStream(Encoding.UTF8.GetBytes(package.GetValue(strInputName)));
log.Debug("InputObject:" + strInputName);
log.Debug("Filename for binary:" + strFileName);
log.Debug("Destination StructureGroup:" + sg_Destination);
Publication contextPub = utils.getPublicationFromContext(package, engine);
TcmUri uriLocalSG = TemplateUtilities.getLocalUri(new TcmUri(contextPub.Id), new TcmUri(sg_Destination));
TcmUri uriLocalMMComp = TemplateUtilities.getLocalUri(new TcmUri(contextPub.Id), new TcmUri(itemComponent));
StructureGroup sg = (StructureGroup)engine.GetObject(uriLocalSG);
Component comp = (Component)engine.GetObject(uriLocalMMComp);
String sBinaryPath = engine.PublishingContext.RenderedItem.AddBinary(inputStream, strFileName, sg, "nav", comp, "text/xml").Url;
//Put a copy of the path in the package in case you need it
package.PushItem("BinaryPath", package.CreateStringItem(ContentType.Html, sBinaryPath));
}
catch (Exception e)
{
log.Error(e.Message);
}
finally
{
if (inputStream != null)
{
inputStream.Close();
}
}
}
}
I think the code is pretty self explanatory. This publishes a binary of type text/xml, but there should be no issue converting it to do a plain text file.
I think you can use multimedia component to store your .htaccess. Even if you will not be able to upload file without name (Windows limitation), you will be able to change filename later, by modifying BinaryContent.Filename property of multimedia component. You can then publish this component seperately, or use AddBinary method in one of your templates.
There's also a user schema where you can change some other rules: "\Tridion\bin\cm_xml_usr.xsd", but you will not be able to allow empty filenames