Add images to Google Document via Google Apps Script - google-docs

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.

Related

Form Thumbnail URL for SharePoint large video Files

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!

how to replace space in image url in nodejs

I am fetching data from an api and it contains image urls. When i try to display the images it is not showing any picture. when i logged using console.log(service.coverImage), i was able to display the image urls. for example
https://s3.eu-west-2.amazonaws.com/ererf3wery/Hillside Plaza Hotel 5cdebeaf34157a0026526f0d/providerImage/hph.jpeg
You notice the link breaks and it doesn't go to the image directly, now i cannot change this in the database. How can i solve this in Nodejs to replace the places so that it becomes complete.
I have used methods like replace and encodeURIComponent but not helping
thank you in advance
The image url looks fine, if you are not able to see the image in web page, try to remove protocol from it.
url = url.replace("https:", "");
If that doesn't work, then try removing spaces as you wanted:
let url = "https://s3.eu-west-2.amazonaws.com/ererf3wery/Hillside Plaza Hotel-5cdebeaf34157a0026526f0d/providerImage/hph.jpeg";
url = url.replace(/\ /g, "%20");
console.log(url)

Displaying user information on Google Map on click of the location using node js, express and mongodb

I am doing a small project which takes user information like name, age, location etc and display it on the Google map on click of that location.
I have completed the first part i.e., taking user information using node js, express and Mongo db.
I am not understanding how to go to next part and display that information on Google maps on click of that location.
Any tutorial or pointers would be helpful on how to go forward. Thanks.
If you are asking how to display markers on webpage you might want to check google documentation:
To create a marker on map documentation is here, also if you
want to add a custom marker image sample is here.
To display the information on the google maps on marker sample
here.
I'm assuming you are storing the marker information in your DB, so you can retrieve it from there, just create a schema for marker and markerinfo.
Way to add a marker to map with onClick event:
map.addListener('click', function(e) {
placeMarker(e.latLng, map);
});
function placeMarker(position, map) {
var marker = new google.maps.Marker({
position: position, // {lat: -100.000, lng: 100.000};
map: map
});
map.panTo(position);
}
Getting marker from express api with jQuery:
$.getJSON("/api/marker/1", function(json) {
placeMarker(json,map);
});
Ping me if you have questions;
Good luck;

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.

SharePoint 2010 - Picture Library SlideShow Web Part

I am using the Picture Library SlideShow Web Part and I want to show the actual image not the preview image.
I found a solution to use JQUERY to expand the width of the preview image to the width I want on the page, but this of course ruins the quality of the image.
The actual image the was uploaded will be in a path: /Home%20Page%20Banners/Banner2.jpg
SharePoint creates a preview images and placed is in another path and renames the file, for example: /Home%20Page%20Banners/_w/Banner2_jpg.jpg
My question is how can I get the preview image to show the acutal full image that was uploaded and not the scaled down image?
Picture Library SlideShow web part class is marked a sealed, so there is no way to extend it.
But it could be customized on the client side, to be more precise functions from Slideshow library (imglib.js) could be overridden.
How to display full-sized(original) images in Picture Library Slideshow web part
The solution described below allows to display original images in Slideshow web part. In order accomplish it the function for initializing picture in slideshow should be overridden (see the code below).
Step 1. Save below JavaScript code to the file, for example in SlideshowObjectInitializer.txt and upload it to SiteAssets Library
<script type="text/javascript">
function SlideshowObjectInitializer() {
ShowPic = (function(ShowPicOrig) {
return function() {
var ssObj = arguments[0]; //SlideShow object
var curPicIdx=ssObj.index; //current picture index
ShowPicOrig.apply(this, arguments); //call original ShowPic
//apply some changes to display original picture in SlideShow control
ssObj.image.src = ssObj.linkArray[curPicIdx]; //display original image instead of web image
//change picture & container size to auto instead of fixed (by default web image size is used)
ssObj.image.setAttribute('height','100%');
ssObj.image.setAttribute('width','100%');
var cell = ssObj.cell;
cell.style.width = 'auto';
cell.style.height = 'auto';
cell.style.display = '';
var pcell = ssObj.cell.parentNode;
pcell.style.width = 'auto';
pcell.style.height = 'auto';
};
})(ShowPic);
}
ExecuteOrDelayUntilScriptLoaded(SlideshowObjectInitializer, 'imglib.js');
</script>
Step 2. Add Content Editor web part (CEWP) on page where Slideshow web part is located and in the Content Editor tool pane, under Content Link, type /SiteAssets/SlideshowObjectInitializer.txt.
For more details about customizing Slideshow web part please follow this blogpost

Resources