How do you reference images that are stored in your Filing Cabinet when trying to embed them into HTML.

For example, when using logos in your emails how do you reference them?

When constructing emails that are used within SuiteScript you would think you’d need to construct the emails with both the url of the file AND the domain of your Netsuite instance, perhaps coded like this:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
import url = require("N/url");
import file = require("N/file");

const fn () => {

	const fileId = 0;
	const domain = url.resolveDomain({
        hostType: url.HostType.APPLICATION
    });
    const imgFile = file.load({ id: fileId });
    // construction of the full URL for use outside Netsuite, right?
    const imgUrl = `${domain}${imgFile.url}`;
	return `<img src="${imgUrl}">`;

}

However, the result from this function is https://0000.app.netsuite.comhttps://0000.app.netsuite.com/yourFileLocation

As you can see it prepends the domain twice to your URL construction!

Upon uploading the file to the Document storage in Netsuite, if you have the checkbox Available Without Login this will provide the full url when using the url property.

Therefore, you don’t need to obtain the domain value using the url module.

Simply fetch the url property from the file upon loading it.