In my windows phone 8 app, I have some images in IsolatedStorge under a folder named 'ProfileImages'.
Suppose I want to get a URI to an image named 'a.jpg' :
In C# I can do it as,
Uri uri = new Uri("/ProfileImages/a.jpg", UriKind.Relative);
Since Windows::Foundation::Uri in C++/CX, doesn't support relative Uri, I tried something like
this->imageUri = ref new Uri("appdata:/ProfileImages/a.jpg");
But this didn't work out. What's the solution?
Related
I'm using the https://developer.api.autodesk.com/oss/v2/buckets/:bucketKey/objects/:objectName endpoint to download an item (a Revit model) from BIM 360. Using this documentation. The file gets downloaded fine and the contents are correct however, after downloading, the file name is the GUID of the file (4aac519c-ab91-42a5-85c5-f023c82d4736.rvt) , not the 'displayName' of the file (my file.rvt) . I'm getting the file name like so:
var headervalue = resp.Headers.FirstOrDefault(x => x.Name == "Content-Disposition")?.Value;
string contentDispositionString = Convert.ToString(headervalue);
ContentDisposition contentDisposition = new ContentDisposition(contentDispositionString);
fileName = contentDisposition.FileName;
I've used the same method on another project and it's working fine. The content and the file name of the file both are correct. However somehow the endpoint is behaving differently on this project.
Any pointers what could be the issue here?
I'm not sure if this is mentioned somewhere in the documentation but I don't think you should rely on the Content-Disposition of the response headers for this. If you want to get a filename for whichever object you're downloading, you should always get it from the actual item record (obtained in the 3rd step of the tutorial you linked to).
I was having a problem running the Windows version of a universal app. I am trying to connect the app to facebook using OAuth. On the Windows Phone side I can set my redirect Uri to something custom like http://facebook.com and it works fine - the result comes back with the correct values. But when I try to use this in Windows Store side, it does not work. Basically the result doesn't come back with the access token or anything else, and it looks like it returns the original start Uri instead. furthermore it does not actually go to the sign in page, it skips over that part.
This Uri does not work in Windows Store (but it works in Windows Phone)
.
Uri endUri = new Uri("http://facebook.com", UriKind.Absolute);
This Uri works in Windows Store
var redirectUri = WebAuthenticationBroker.GetCurrentApplicationCallbackUri().ToString();
Uri endUri = new Uri(redirectUri, UriKind.Absolute);
This is the code that is consuming the Uri.
#if WINDOWS_PHONE_APP
WebAuthenticationBroker.AuthenticateAndContinue(startUri, endUri, null, WebAuthenticationOptions.None);
#endif
#if WINDOWS_APP
WebAuthenticationResult result = await WebAuthenticationBroker.AuthenticateAsync(WebAuthenticationOptions.None, startUri, endUri);
await ParseAuthenticationResult(result);
#endif
Does anyone know why this is?
I am having an issue with the server.mappath method. My current code is:
var imageroot = Server.MapPath("~/Images/Property/");
var foldername = rPropertyId.ToString();
var path = Path.Combine(imageroot, foldername);
When I upload this path into my database, I expect to see the following URL:
/images/property/1/filename.jpg
But what I actually see is this URL:
C:\Users\gavin\Dropbox\My Web Sites\StayInFlorida\Images\Property\1\filename.jpg
How do I get around this? I'm assuming I have to change the MapPath method, but I've tried a few things but I've had no luck.
The Server.MapPath method returns a file system path. What you want is a (relative) URL. Paths and URLs are completely different things. Typically, you need a path if you want to manage files in your server side code, and you need a URL is you are providing access to those files to visitors via hyperlinks. URLs can be constructed from strings:
var url = string.Format("/Images/Property/{0}/{1}", rProprtyId, filename)
My idea is to save the images which the user uploads outside the context path as follow:
D:\somefolder\myWeb\web-app\
D:\somefolder\imagesOutsideContextPath\
The code for that is the next (working locally):
String path = servletContext.getRealPath("/");
String parentFolder = new File(path).getParentFile().getParent();
String imagesFolder = parentFolder + "\\imagesOutsideContextPath";
Another idea (if this one doesn't work on server) would be to save the images in the current user's home folder as #HoàngLong suggested me.
But I'm not able to load the images from the view. I think this article from official documentation is not valid for that purpose. The next code desn't load anything:
<img src="D:\\somefolder\\imagesOutsideContextPath\\bestImageEver.jpg" alt="if I don't see this message, I'll be happier">
How could I use the real path instead the an url path to load these images?
There's a new plugin that makes this easy, check out http://grails.org/plugin/img-indirect
Create an action
def profileImage() {
String profilePicturePath = "${grailsApplication.config.profilePictureDirectoryPath}/${params.id}"
File file = new File(profilePicturePath)
response.contentType = URLConnection.guessContentTypeFromName(file.getName())
response.outputStream << file.bytes
response.outputStream.flush()
}
and then call this action with image name in params like:
<g:img uri="${grailsApplication.config.grails.serverURL}/controller/profileImage/${user?.profilePicture?.fileName}"/>
I have declared the image directory file in my config.groovy file like:
profilePictureDirectoryPath = '/opt/CvSurgeon/profileImages'
You can set the src to an action. With that your user will not know where your images are stored (security) and you can easily change your logic to display them.
In the action, just get your image and print the bytes. Example here.
Firstly, thank you for your reference.
It's insecure to load images using real path. The web browser should know nothing about how the pictures are saved on server, therefore not aware of the folder structure.
What I mean is that the system should use a specific URL for all your pictures, such as http://your_app/photo/user/{id}. Then to that URL, you can construct an action which gets id as a parameter, look up the photo in your file system(of course you must store the picture folder in configuration), and render the photo back.
I have Windows Phone 8 app in which I want to include my own 10 MP3s. I included them in /Assets, but a call like
using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
{
songs = store.GetFileNames("*.mp3").ToList();
Console.WriteLine("Found {0} files ", songs.Count());
}
keeps returning that the # of MP3s in my store is 0.
I tried putting the MP3s in Content, Assets, Resources and set Copy Always option, but to no avail.
Any help will be appreciated.
if you set your files as "Embedded Resource", you can get a list of files at runtime.
Here is how you can do this:
Set the Build Action of your files as "Embedded Resource".
Use Assembly.GetCallingAssembly().GetManifestResourceNames() to enumerate the resources names
string[] GetResourcesNames()
{
return Assembly.GetCallingAssembly().GetManifestResourceNames();
}
The files is not copied to isolated store for your app, but you can get them by the uri:
var mymp3file = new Uri("Assets/HomersDoh.mp3", UriKind.RelativeOrAbsolute);