UWP - How to read .jpg from Desktop inside of app - exception

The functionality I am needing for my app is that if a user copies an image file (for example, a .jpg file in their Desktop folder), I need to extract that file from the clipboard and display it in my app.
I can already extract the storage file from the clipboard, and get the file path. But when I try to read the file path into a BitmapImage, I received a System.UnauthorizedAccessException error, because the image is not located in the app's folder.

It sounds like you are trying to open the file by path rather than directly using the StorageFile returned by the file picker.
Your app doesn't have direct access to most of the file system (including the downloads directories) and can access such files only indirectly via the file system broker. The StorageFile object works with the broker to open files the use had authorized and provides a stream of the files contents for the app to read and write to.
You can use Xamarin.Plugin.FilePicker or FilePicker-Plugin-for-Xamarin-and-Windows .

You may x:Bind path to XAML Image
<Image>
<Image.Source>
<BitmapImage UriSource="{x:Bind GetAbsoluteUri(Path)}"/>
</Image.Source>
</Image>
Code behind:
private Uri GetAbsoluteUri(string path)
{
return new Uri(Path.GetFullPath(path), UriKind.Absolute);
}
Try, hope it'll work :)

Related

Selenium ide to locate a file and store its path info from any computer

currently in my test scripts for automated file upload to browser, the paths are already defined in the value column
command type
target //input[#type='file']
value /Users/.../.../.../filename.extension
in such cases, this script is unable to run on other computers because the path would be different.
my question will be is
is there a way to locate the file in a general folder (for example file is downloaded and in the "download" folder), by using selenium ide can we get the path of the file (/Users/.../downloads/filename.extension)
store the path of the file with its extension into a notepad which i will be using it for multiple test of file uploads later on.
right now if my colleague needs to run the script from his computer, he have to manually change the value to his path.
You could use a suite file that contains a "setup" file to only change the file name in 1 place and the variable is shared across tests in the suite. You could also select an agreed up on place to store the files: c:\test_info\image.jpg.
Or you can make the file available by URL & not local, Unfortunately javascript prevents that for security: How to get the current file path in javascript
Unfortunately I can't think of any other good way unless you all have the same path in a home directory and could do something like ~/test_dir/photo.jpg

how to get browsed file location by user when he wants to download a file

this is my html code to make user to download a file and it is hitting controller
window.location.href="#routes.ListManagementController.downloadList("+listName+")?listname="+listName;
this is my controller code:
String listName = Form.form().bindFromRequest().get("listname");
response().setContentType("application/x-download");
response().setHeader("Content-disposition", "attachment;filename="+listName+"_data_export.csv");
The above two respose() statements make a pop up to download a file I want the browsed file location
File file = new File("C:/csv/" + filename);
So, using servlet api we can write the content into browsed file location using respose.getOutputStream() method. In play there are is no support for servlet. I want browsed file location selected by user so that i can give that location to File and write the file over there.
You can't get the location of a directory on the client, and even if you could, your server side could wouldn't be able to write to it (since it would usually be on a different computer).

Load local image, modify it and save back to same file

File input allows user to access a local file from browser. Is it possible to load a local file given by file input, modify it and save it back to same local file? I know that HTML5 allows creating writeable filesystem, but basically it seems to be abstract directory.
For security reasons, I don't think the browser can overwrite the local file. Using the File-System API you could only copy the contents of the local file to the sandboxed File-System API directory(found under various obfuscated file names). All manipulation/saving would be done in AppData.
Perhaps displaying the modified image on the screen, right click, save-as to the given file location would also be suitable? (other than that I think you have to upload the image to a server and download it back again)

turn folder into a zip file

I have a folder on my desktop and i want to convert it into a .zip file. It shouldnt ask me were to save it but just save it straight to my desktop or any folder i specified.
I tried ASZip, fZip etc. but i can't get it to work. There isn't any of them that seem to let me just add a folder and zip it.
I was only able to create a byteArray wit ASZip but when i saved it, it left me with a file that was not able to be opened.
Would it be possible to achieve what i want without the use of an external library?
Any help would be appreciated.
You can't actually zip a folder but you can zip all the contents inside the folder. You would have to use FileReferenceList to load in flash all the files inside the folder.
FileReferenceList allows you to have multiple selection in the browse window.
Then you would have to pass all these files to the zip managing library and get a ByteArray from it.
This byte array you would localy dump inside a "yourFileName.zip" by using FileReference.save().
The application cannot save the file to a predetermined location. The user has to pick the location using the "save to" prompt.

Google Maps Markers which image files are within a jar file

My web application is based on Google Maps API and I have problems trying to access an image which is within a jar file.
I want to be able to do two things:
Show a marker in the javascript map.
Show a marker in a static map.
In both cases I need to provide the path to the image file. This image is inside a jar file which is located in the /WEB-INF/lib folder once the web application is deployed in the server.
I thought that the following line would work:
iconMarker.image = "WEB-INF/lib/cimCore.jar!/META-INF/resources/img/" + ilMarker.icon;
But it shows the following error in the client browser:
"NetworkError: 404 No Found- http://ip/cimWeb/WEB-INF/lib/cimCore.jar!/META-INF/resources/img/gsearch.png"
The path is OK so I guess that accessing by means of '!' character is not the proper way.
Any idea?
You'll have to use a servlet which will load the image bytes from the classloader, and stream these bytes to the response :
Use MyServlet.class.getResourceAsStream("/META-INF/resources/img/gsearch.png") to get an input stream on the image
call response.setContentType("image/png")
get the response output stream
read all the bytes from the input stream and write them to the output stream
Note that most of the MVC frameworks have support for mapping a pattern of URLs to classpath resources, or to at least implement one part of the algorithm above for you.
Or you can just extract these images out of the jar file, and put them in the webapp's tree of externally accessible resources.
Side note: WEB-INF is, by design, not accessible from the outside. If what you wanted to do was possible, anybody could steal the jar files and configuration of any Java-based webapp.