From CMIS how do I get the thumbnail placeholder for Alfresco? - thumbnails

I understand that the following URL will give me the thumbnail of a document or the placeholder image, if there isn't a thumbnail. This works because of the ph=true at the end.
http://cms.mydomain.com:8080/share/proxy/alfresco/api/node/workspace/SpacesStore/" + childId + "/content/thumbnails/doclib?ph=true
I have also found that the following server side code will get me the ContentStream of the thumbnail image.
OperationContext context = session.createOperationContext();
context.setRenditionFilterString("cmis:thumbnail");
CmisObject doc = session.getObject(id, context);
List<Rendition> renditions = doc.getRenditions();
if (renditions.size() > 0) {
Rendition rend = renditions.get(0);
cs = rend.getContentStream();
}
The problem with this is it does not return the placeholder image if there isn't a thumbnail, like the first URL.
For the server side how would I retrieve the appropriate placeholder image when there isn't a thumbnail? For example for docx and xlsx files.
Thanks,
Jon

I think in this case the most effective way to retrieve thumbnails (doclib or a placeholder) is to call directly the REST Alfresco Service.
I'm not 100% sure but CMIS rendition response from an Alfresco Server contains only existing renditions. There's no placeholder provided in CMIS renditions part like the one provided by the Alfresco REST url.

The key here is in if (renditions.size() > 0) -> this is exactly what the webscript does.
But what the REST webscript also does is to ad an else -> so if there aren't renditions so far, it fill determine mimetype and fetch the corresponding placeholder.
You should do the same in your code to make it fetch placeholder -> add an else and then find the placeholder for that image.

Related

Intercept and edit multipart form-data POST request body in Browser

I've got a site that accepts file uploads which are sent as multipart/form-data within a POST request. To verify that the upload, which shows the filename afterwards, is secured against XSS I want to upload a file which contains HTML Tags in the filename.
This is actually harder than I expected. I can't create a file containing < on my filesystem (Windows). Also, I don't know a way to change the filename of the file input element inside the DOM before the upload (which is what I would do with normal/hidden inputs). So I thought about editing the POST body before it's uploaded, but I don't know how. Popular extensions (I recall Tamper Data, Tamper Dev) only let me change headers. I guess this is due to the plugin system of Chrome, which is the Browser I use.
So, what's the simplest way of manipulating the POST requests body? I could craft the entire request using cUrl, but I also need state, lots of additional parameters and session data etc. which gets quite complex... A simple way within the Browser would ne nice.
So, while this is not a perfect solution, it is at least a way to recreate and manipulate the form submit using FormData and fetch. It is not as generic as I'd like it to be, but it works in that case. Just use this code in the devtools to submit the form with the altered filename:
let formElement = document.querySelector('#idForm'); // get the form element
let oldForm = new FormData(formElement);
let newForm = new FormData;
// copy the FormData entry by entry
for (var pair of oldForm.entries()) {
console.log(pair[0]+': '+pair[1]);
if(typeof(pair[1]) == 'object' && pair[1].name) {
// alter the filename if it's a file
newForm.append(pair[0],pair[1],'yourNewFilename.txt');
} else {
newForm.append(pair[0],pair[1]);
}
}
// Log the new FormData
for (var pair of newForm.entries()) {
console.log(pair[0]+': ');
console.log(pair[1]);
}
// Submit it
fetch(formElement.action, {
method: formElement.method,
body: newForm
});
I'd still appreciate other approaches.

Facebook Graph API - retrieve photos from album INCLUDING source (original photo url)

I retrieve the list of photos in an album like following:
String url =
"https://graph.facebook.com/v2.5/" +
albumId +
"/photos?fields=created_time,height,id,images,picture,name,updated_time,width";
There seems to be no field source in the album request... The picture array contains a lot of image urls, but it seems that it does NOT contain the original url. I see images where I can't find the original image in the picture array...
So the only solution I found is to make a request for every image like following:
String url = "https://graph.facebook.com/v2.5/" + id + "?fields=source";
And extracting the source value from this answer.
Is there any better approach? I know width, height and many urls, but I need the original image url as well... It's somehow weird to make a request for every single image just for that information...
You can get all this data in one go, by using the field expansion syntax:
/album-id?fields=photos{created_time,height,id,images,picture,name,updated_time,width,source}

Is there a way to programmatically set metadata of an asset?

I added a custom metadata in CQ5 with name ./dc:sample. Is there a way I can programmatically set this metadata for an asset?
I've written a workflow that intercepts the uploaded assets and replaces them with inputstream sent from the third party service. I accomplish this by doing the following in my workflow.
Rendition rendition = resource.adaptTo(Rendition.class);
Asset asset = rendition.getAsset();
InputStream newInputStream = myService.sendFile(is);
asset.addRendition(rendition.getName(),newInputStream,asset.getMimeType());
Question
At this time I would like to set the ./dc:sample metadata to a string like "test checking". Is this possible to do?
You can adapt the Asset to Resource, get its jcr:content/metadata grandchild and adapt it to ModifiableValueMap:
Resource metadataRes = asset.adaptTo(Resource.class).getChild("jcr:content/metadata");
ModifiableValueMap map = metadataRes.adaptTo(ModifiableValueMap.class);
map.put("dc:sample", "test checking");
resourceResolver.commit();

Fiddler Script - SaveResponseBody()

I want to save all png images that are loaded along with some webpage into a separate folder.
I am using below code with in Fiddler Script [CustomRules.js].
static function OnBeforeResponse(oSession: Session)
{
if(oSession.url.EndsWith(".png"))
{
oSession.SaveResponseBody();
}
//Actual content of OnBeforeResponse function.
}
Problem here is, I was unable to find any image got saved within Program files/Documents.
Where do “SaveResponseBody()” will save the HTTP Response Body?
Can we give our own custom folder?
My Fiddler version is (v4.4.5.6)
The default SaveResponseBody() method saves the files to your \Documents\Fiddler2\Captures\ folder. If you want to use a different name, use the overload that accepts a filename. You should check the Response's status code is 200 to ensure that you're not trying to save off HTTP/304 responses which won't contain a body. Also, rather than looking at the URL, you probably want to check the response's type.
So you end up with something like this:
if ((oSession.responseCode == 200) &&
oSession.oResponse.headers.ExistsAndContains("Content-Type", "image/png"))
{
SaveResponseBody("C:\\temp\\" + oSession.SuggestedFilename);
}
Note: The manual way of doing this would be to go to the QuickExec box below the Web Sessions list, type select png and hit Enter, then click File > Export > Selected Sessions > Raw Files.

Manage Titles when Uploading Multiple Images

It would be great if we could manage the titles of each image that we upload when uploading multiple images. This way I could select each image that I want to upload, title them, then hit the upload button. Right now one must either upload one by one or have all the selected images have the same title.
Kinda like Facebook or Panoramio where it's easy to manage the titles of the images before uploading.
This isn't natively supported in Fine Uploader at the moment, but I've opened up a feature request and tentatively scheduled it for the 3.7 milestone. In the meantime, you can certainly provide your own UI elements to allow users to provide alternate names for each upload-able item and pass these new names as a parameter. Server-side, you would have to parse this parameter and associate it with the uploaded item. Fine Uploader will have to adopt a parameter name that contains the user-supplied alternate filename anyway (and the server will have to be aware of this convention and parse this parameter), since we won't be able to change the value file input field sent along with the multipart encoded request.
use this:
var uploader = $('.uploader'),
titleBox = $('input[type=text]');
uploader.fineUploader({
request: {
endpoint: 'path/to/url'
},
formatFileName: function (name) {
var title = titleBox.val() + ' - ' + name + '';
titleBox.val('');
return title;
},
});
uploader.on('submit', function (event, id, name) {
uploader.fineUploader('setParams', {title: titleBox.val()}, id);
});