Reputation: 21
I have create the UWP which include sign up step and in sign up step I would like user to upload the pictures and I wish when user upload it's will save in the assets folder automatically I would like to know 2 things
How do I can access the picture (May be from camera roll or take a picture)
How do I can save that picture user upload to asset folder
Thank you
Upvotes: 0
Views: 1277
Reputation: 17855
To let the user pick it from his pictures library:
var picker = new FileOpenPicker
{
SuggestedStartLocation = PickerLocationId.PicturesLibrary,
FileTypeFilter = {".jpg", ".jpeg", ".png", ".gif"}
};
var file = await picker.PickSingleFileAsync();
To take a photo:
var capture = new CameraCaptureUI
{
PhotoSettings =
{
Format = CameraCaptureUIPhotoFormat.Jpeg
}
};
var file = await capture.CaptureFileAsync(CameraCaptureUIMode.Photo);
In both cases the result is an IStorageFile
.
I'm not really sure, what you mean by "asset folder". The Assets
folder in your project is a part of the application and only contains the files that were distributed with the original application package. You can't save additional files there.
If you want to save the files locally, you can use one of the application storage folders, e.g. LocalFolder
:
await file.CopyAsync(ApplicationData.Current.LocalFolder, "profile.jpg");
If you want to upload it to a server and have it accessible globally to all users, you'll of course need some server side code for that, e.g. an upload page to post the image to:
var uri = new Uri("http://my.server.com/upload");
var uploader = new BackgroundUploader();
var upload = uploader.CreateUpload(uri, file);
await upload.StartAsync();
You could then save the file somewhere on the server and make it accessible to the apps. Check out the official sample to see a working implementation of file upload.
Upvotes: 1