Form Thumbnail URL for SharePoint large video Files - sharepoint

I am trying to form SharePoint file's thumbnail URL (in Office 365) as mentioned in https://www.techmikael.com/2020/01/retrieving-thumbnailspreviews-for.html. This uses SharPoint site ID, List ID and file item's Unique ID to generate thumbnail URL.
/_api/v2.0/sites/${this.context.pageContext.site.id}/lists/${listId}/items/${itemUniqueId}/driveItem/thumbnails/0/${maxHeight}/content${noRedirect}
But I always get error message 404 Not Found. I used search API to verify that the thumbnail URL exists in "PictureThumbnailURL" field.
I also tried with _api/v2.1/... but get the same error. Just to be sure I ran the sample SPFx web part solution available here: https://github.com/pnp/sp-dev-fx-webparts/tree/main/samples/js-msgraph-thumbnail and get the same 404 Not Found error for images.
I have already been using getpreview.ashx but I don't see preview for large video files but get the preview URL in the search even for those large files.
I can't use search API since search result may not be immediately available to get and save the thumbnail URL.
Is there any other way to get the picture thumbnail URL using REST API in SPFx?

I found a way to generate the thumbnail URL using drive API. There are properties on File object VroomDriveID and VroomItemID. Using these properties we can format the link as below:
https://{tenantname}.sharepoint.com/_api/v2.1/drives/${VroomDriveID}/items/${VroomItemID}/thumbnails/0/c400x99999/content?preferNoRedirect=true
Below is sample code to get these properties from SharePoint:
let thumbnailURL = "";
let uniqueID = "{file's unique id}";
let resolution = "c400x99999";
let caml: ICamlQuery = {
ViewXml:
<View><Query><Where><Eq><FieldRef Name='UniqueId' /><Value Type='Text'>${uniqueID}</Value></Eq></Where></Query></View>
};
// get list items
const fileItems: IItems = await sp.web.lists.getByTitle("DocLibTitle").getItemsByCAMLQuery(caml, 'FieldValuesAsText, File/VroomDriveID,File/VroomItemID');
console.log("Items: ", fileItems);
let VroomDriveID = fileItems[0]["File"]["VroomDriveID"];
let VroomItemID = fileItems[0]["File"]["VroomItemID"];
thumbnailURL = "https://{tenantname}.sharepoint.com/_api/v2.1/drives/${VroomDriveID}/items/${VroomItemID}/thumbnails/0/${resolution}/content?preferNoRedirect=true";
console.log(thumbnailURL);
I hope this helps!

Related

Image Description in Liferay Web Content Template

In my web content structure, I have a Document and Media type field so that users can select an image. In the web content template, I want to get the selected image's description so that I can fill in the alt text for the image.
How do I go about doing getting the description information of that selected image in the template?
You can get fields like description, you need to first get the image ID. Then you'll use the DLFileEntryLocalServiceUtil to get the file. Once you get the file, you can call the function to get the description.
<#assign imgID = Image.getData()?string?split("/")[5]?split("?")[0]>
<#assign fileEntry = staticUtil["com.liferay.portlet.documentlibrary.service.DLFileEntryLocalServiceUtil"]>
<#assign file=fileEntry.getFileEntryByUuidAndGroupId(imgID, groupId) >
${file.getDescription()}
You can get the other metadata of the document/image by calling one of the other functions for the DLFileEntryModel.

Getting the URL for a file's metadata page in Liferay

I've been tasked with creating a new column in the list of files in a Liferay 6.2 document library. For each file, that column should display a link with the text "Details" and the URL for that file's metadata page. In view_entries.jsp, I'm looking to add this field to a ResultRow. All I've been able to find so far, is DLUtil's getPreviewURL, which only seems to give me the URL for downloading the file itself, rather than leading to the metadata page. The Title column uses a TextSearchEntry, which ends up displaying with the URL I want, but I can't figure out how to either get that URL from it or change the text it displays the link with.
PortletURL rowURL = liferayPortletResponse.createRenderURL();
rowURL.setParameter("struts_action", "/document_library/view_file_entry");
rowURL.setParameter("redirect", HttpUtil.removeParameter(currentURL, liferayPortletResponse.getNamespace() + "ajax"));
rowURL.setParameter("fileEntryId", String.valueOf(fileEntry.getFileEntryId()));
In this code, fileEntry is the current document. To get the URL to the preview page, it's just rowURL.toString().

Building a list of downloadable items in Orchard 1.6

I'm fairly new to Orchard and I'm wondering about the "best" way of building a basic list of documents with a download link?
Say the scenario is this, I want to make a list of newsletters, the news letter are in PDF format and the users should be able to download then straight from the list view.
An admin, should easily be able to add a new newsletter and it should turn up in the list.
My current train of thought is to, all through the dashboard,
create a content type "Newsletter" with a title field and a Media picker field, using the media picker field to upload the PDF file.
Then create a query, with the filter on Content type "Newsletter"
Create a projection pointing to the query
However, this only gives me a list of content items, showing their title as links back to the actual content item.
I've tried adding a layout to the query and set it to display properties instead of content. By doing that I can get a list where I can control the "output" a bit more. And I've gotten it to list the title and by doing a Rewrite and putting in the MediaPicker.Url, it also displays the URL in the list. This is all good but here I get stuck..
As the MediaPicker.URL outputs the url in the format like ~/media/default/xyz/filename.pdf, I cant just put it into a a href, it doesn't give a correct download link to the file.
Soo, question is, am I thinking and doing this totally the wrong way or am I missing something obvious? All ideas and suggestions and more then welcome.
Use or adapt the following template override in your theme:
#{
var url = Model.ContentField.Url;
}
#if(Model.ContentField.Url != null) {
if (url.StartsWith("~/")) {
url = Href(url);
}
<div class="media-picker-field attachment-pdf">
<span>download</span>
</div>
}
Modify the text as needed. This template was a Fields.MediaPicker-PDF.cshtml that was used for a media picker field named PDF.

Display image in a packagedapp/extension after selecting from Google Drive

My packaged app gets images from google drive and then display them on the side. But I can't get the images to be displayed. I am trying to get the url of the image so that I can put that url in an image source. The image url that I am getting is actually an html page rather than jpeg, png etc. I have looked at the reference guide for google picker but nothing seems to work.
I am using this
function pickerCallback(data) {
if (data.action == google.picker.Action.PICKED) {
var fileId = data.docs[0].id;
fileName = data.docs[0].name;
imgURL = data.docs[0].url;
}
I want to use imgURL as the source for image selection but imgURL is not something like "https//:www.example.com/image.jpg. It is rather an html page I want something that ends with file type only then it will be able to display the image. Please let me know how can I get the image to be displayed in html page of my packaged app after selecting it from google drive.
You should fetch the metadata of the image, then use the webContentLink of the image, then the user can view it in a logged in browser. See the documentation on downloads for more information.

Add images to Google Document via Google Apps Script

How can you add images to a Google Document (not Spreadsheet or Presentation) via Google Apps Script. I don't see an addImage method. Surely the team would not have left this out.
http://code.google.com/googleapps/appsscript/class_document.html
From the docs:
function insertImage() {
// Retrieve an image from the web.
var resp = UrlFetchApp.fetch("http://www.google.com/intl/en_com/images/srpr/logo2w.png");
// Create a document.
var doc = DocumentApp.openById("");
// Append the image to the first paragraph.
doc.getChild(0).asParagraph().appendInlineImage(resp.getBlob());
}
http://code.google.com/googleapps/appsscript/class_documentapp_listitem.html#appendInlineImage
I'm not sure if you can upload an image. But you sure can insert it into a Paragraph via a url.

Resources