Accessing Local Resource (local directory- outside project) in Vaadin 14/RapidclipseX IMG component - vaadin14

How to access the local image file from my hard drive (outside project folder) in the image component (to make an image gallery)? How to write the path of the file? in Vaadin 14/RapidclipseX.
It only takes either path from the project or URL. In my project users have to upload the images and I want to make a gallery that will show the images.
I tried all the below way but didn't work:
D:\\Canavans\\Reports\\256456\\424599_320943657950832_475095338_n.jpg
D:\Canavans\Reports\256456\424599_320943657950832_475095338_n.jpg
code (Tried this way as well):
for(final File file: files)
{
System.out.println(file.getName());
this.log.info(file.getName());
this.log.info(file.getAbsolutePath());
final String path = "file:\\\\" + file.getAbsolutePath().replace("\\", "\\\\");
this.log.info(path);
final Image img = new Image();
img.setWidth("300px");
img.setHeight("300px");
img.setSrc("file:\\\\D:\\\\Canavans\\\\Reports\\\\256456\\\\IMG20171002142508.jpg");
this.flexLayout.add(img);
}
Please Help! Thanks in advance. Or is there any other way to create an image gallery?

Hmm as far as I know if you want to access resources outside the resource folder you can create a StreamResource and initialize the image with that. If you want to use the images "src" property then the file has to be inside one of Vaadin's resource folders (for example the 'webapp' folder).
Here is a simple example on how to create the image with a StreamResource:
final StreamResource imageResource = new StreamResource("MyResourceName", () -> {
try
{
return new FileInputStream(new File("C:\\Users\\Test\\Desktop\\test.png"));
}
catch(final FileNotFoundException e)
{
e.printStackTrace();
return null;
}
});
this.add(new Image(imageResource, "Couldn't load image :("));
Hope this helps :)

Related

SAP HYBRIS : how to use media to convert csv file to media hmc

I am a beginner in the Sap Hybris. I created a CronJob that works perfectly. which returns all the products with status approved and generated CSV file in local C://...
But I want to create or convert my CSV file to a media in HMC MEDIA? can someone help me?
I already have gone through Hybris wiki but I didn't understand.
Thank u for all !!
To achieve this, you only need to create your Media object, and attach your file to the created object, something like :
private MediaModel createMedia(final File file) throws MediaIOException, IllegalArgumentException, FileNotFoundException
{
final CatalogVersionModel catalogVersion = catalogVersionService.getCatalogVersion("MY_MEDIA_CATALOG", "VERSION");
MediaModel mediaModel;
try
{
mediaModel = mediaService.getMedia(catalogVersion, file.getName());
}
catch (final UnknownIdentifierException e)
{
mediaModel = modelService.create(MediaModel.class);
}
mediaModel.setCode(file.getName());
mediaModel.setCatalogVersion(catalogVersion);
mediaModel.setMime("text/csv");
mediaModel.setRealFileName(file.getName());
modelService.save(mediaModel);
mediaService.setStreamForMedia(mediaModel, new FileInputStream(file));
//Remove file
FileUtils.removeFile(file);
return mediaModel;
}

How to Find the Image That is not Found on Ios

I'm getting the error below when I reopen the application to see the image:
Could not initialize an instance of the type 'UIKit.UIImage': the native 'initWithContentsOfFile:' method returned nil
Is it possible to ignore this condition by setting
MonoTouch.ObjCRuntime.Class.ThrowOnInitFailure
to false?
Below method is used to displaying the image
private async Task DisplayImageFromImageUrl()
{
UIImage image;
image = new UIImage(eventImageEntity.EventsImageUrl);
}
while executing the above code "image" showing "null" value.
If your trying to create an image from a URL, you need to use the following code:
if (!string.IsNullOrEmpty(eventImageEntity.EventsImageUrl.Trim()))
{
var url = new NSUrl(eventImageEntity.EventsImageUrl);
using (var data = NSData.FromUrl(url))
{
UIImage image = UIImage.LoadFromData(data);
}
}
Otherwise you will just end up with a Null UIImage. That is what's causing your problem.
EDIT:
If you're trying to get the image from a resource location, then the following is necessary:
This assumes that it's from a specific user created folder:
UIImage image = UIImage.FromFile(#"Assets/NavigationBarAssets/HomePC.png")
OR
This assumes that the image is just say in the root of iOS 'Resources' folder
UIImage image = new UIImage("HomePC.png")

how create document and library in liferay

Requirement: Adding Parent folders, Child folders and Their files to Document and Library from Particular location.
Case-1: If Folder is already exists then get that id and add file
( Here I am using
addFileEntry(repositoryId, folderId,sourceFileName, mimeType, title, description, changeLog, is, size, serviceContext) of DLAppServiceUtil class ).
Case-2: If Folder is not exits add folder then add file
(Here I am using for adding folder
addFolder() method of DLAppServiceUtil class)
My case its gives slow performance. That is the problem.
Which version of Liferay are you using?
The current trend is the following in 6.1+ (well, when it is correctly implemented, but you can build more or less on this with the new DLApp implementation):
Locate the parent folder id. Use the default from the DLFolderConstancts if you don't have any.
Assume the folder exists and try to get it.
It will throw you a NoSuch***Exception if not found. If this is the case, create the folder by hand
You could do something like this:
private Folder getOrCreateFolder(final ServiceContext serviceContext,
final long userId, final Group group, String folderName)
throws PortalException, SystemException {
final long parentFolderId = DLFolderConstants.DEFAULT_PARENT_FOLDER_ID;
final long repositoryId = group.getGroupId();
try {
final Folder prev = DLAppLocalServiceUtil.getFolder(
repositoryId, parentFolderId, folderName);
return prev;
} catch (final NoSuchFolderException e) {
final Folder newFolder = DLAppLocalServiceUtil.addFolder(userId,
repositoryId, parentFolderId, folderName,
"My cool new folder", serviceContext);
return newFolder;
}
}
The docs and stuff are absolutely leaky about why you call the addFolder() that way, take a look on the portal source. It's not that trivial but isn't that hard to get used to either.

Creating Sharepoint Directory Recurisvely

I am attempting to create a set of folders that comes in from a flat file in the manner of.
X/Y/Z
and I would like to create a directory for each of these but my memory of recursion has got me in knotts.
here is my code can someone advise.
public void CreateDirectory(SPFolderCollection oWeb, string folder)
{
SPFolder theFolder = oWeb.Add(folder);
theFolder.Update();
}
public void FolderCreator(SPWeb oWeb)
{
StreamReader reader = new StreamReader(this.txtFolders.Text);
while (reader.Peek() != -1)
{
string folderLine = reader.ReadLine();
if (folderLine.Contains("/"))
{
SPFolderCollection collection = oWeb.Folders["Documents"].SubFolders[folderLine.Split('/')[0]].SubFolders;
CreateDirectory(collection, folderLine);
}
SPFolderCollection newCollection = oWeb.Folders["Documents"].SubFolders;
CreateDirectory(newCollection, folderLine);
}
}
This does not work I am looking for it to do recrusion so if I pass
ABC/DEF/GHI
and
ABC/DEF
it will go and create the folders appropriately.
But I am stuck as how to do that.
The SPFileCollection.Add() methods allow you to pass in the full relative path of a file. So this may be an option assuming you aren't just generating a folder structure, which you may be doing, in which case this won't really work unless you create a temporary file and then delete it to keep the folder path.
web.Files.Add("/sites/somesite/shared documents/foldera/folderb/folderc/somefile.txt", stream);

Create a directory on UNC Path web part sharepoint

I have created a web part which renders a button, on click of this button I want to access the directory of the other machine in LAN. Once I get the access to this Directory I will create a nested directories inside it with different extensions of files, but the problem is when I tries to access this folder by UNC Path it is giving me error like "Could not find a part of the path '\comp01\ibc'". Here comp01 is the computer name which is situated in LAN and ibc is a shared folder on that machine.
Following is the code for button click,
void _btnBackup_Click(object sender, EventArgs e)
{
try
{
//UNC Path --> \\In-Wai-Svr2\IBC
if (!string.IsNullOrEmpty(UncPath))
{
SPSite currentSite = SPControl.GetContextSite(this.Context);
SPWeb parentWeb = currentSite.OpenWeb();
string dir = Path.GetDirectoryName(UncPath);
//If IBC folder does not exist then create it.
if(!Directory.Exists(dir))
Directory.CreateDirectory(dir);
IterateThroughChildren(parentWeb, UncPath);
}
else
{
_lblMessage.Text = "UNC Path should not be empty";
}
}
catch(Exception ex)
{
_lblMessage.Text = ex.Message;
}
}
For UNC paths you need to specify it like this:
either use a C# string literal
String path = #"\\comp01\ibc";
or escape the string like
String path = "\\\\comp01\\ibc"
Try that.

Resources