Reputation: 340
Hi Everyone I am doing a project in which i need to download file from a url.Now I am downloading file and saving that in Personal Folder and it is saving in App directory.I am getting that file through file path and displaying in web view.But if the file is image or Video i cannot see that in Photo albums or gallery of my ipad.
Can anyone of you please help in resolving that problem.
And one more thing where can i find the documents and pdfs that are saved in Personal folder through iPhone or iPad?
Thanks in advance.
Upvotes: 1
Views: 2121
Reputation: 6643
You just save photos to Personal Folder, this is a sandbox folder on iOS. You can use dependency service to write images to system's album.
Firstly create an interface in PCL:
public interface ISavePhotosToAlbum
{
void SavePhotosWithStream(Stream stream);
}
After downloading the image, use this to write in native:
HttpWebRequest aRequest = (HttpWebRequest)WebRequest.Create(urlStr);
HttpWebResponse aResponse = (HttpWebResponse)aRequest.GetResponse();
DependencyService.Get<ISavePhotosToAlbum>().SavePhotosWithStream(aResponse.GetResponseStream());
At last we should implement this Denpendency Service on native platform:
[assembly: Dependency(typeof(SaveToAlbum))]
namespace SavePhotosDemo.iOS
{
public class SaveToAlbum : ISavePhotosToAlbum
{
public void SavePhotosWithStream(Stream stream)
{
var imageData = NSData.FromStream(stream);
var image = UIImage.LoadFromData(imageData);
image.SaveToPhotosAlbum((img, error) =>
{
});
}
}
}
Please notice that: on iOS when you want to write photos to album, we need to add Privacy in info.plist. On iOS 11 add NSPhotoLibraryAddUsageDescription
, iOS 10 add NSPhotoLibraryUsageDescription
.
Upvotes: 3