How to access/download a file or media from Android / IOS using UmbracoApiController as REST API. I tried with
var content = Umbraco.Media(mediaId);
foreach (var child in content.Children)
{
//string url = child.getProperty("umbracoFile").Value.ToString();
medias.Add(child.Url);
// this will give Local Url of the media
//For examle : - d:\\sampleUmbraco\\media\\2\\Login.jpg
}
return medias;
How can i download a media as ByteArrayContent using it's id.
Thanks for your response.
I just want to pass Id to a POST method of a service which will return media as byte array.
I done that Using the following code,
[HttpPost]
public HttpResponseMessage DownloadImage(int id)
{
var media = Umbraco.Media(id).Url;
if (!File.Exists(media))
throw new HttpResponseException(HttpStatusCode.NotFound);
HttpResponseMessage Response = new HttpResponseMessage(HttpStatusCode.OK);
byte[] fileData = File.ReadAllBytes(media);
if (fileData == null)
throw new HttpResponseException(HttpStatusCode.NotFound);
Response.Content = new ByteArrayContent(fileData);
Response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
return Response;
}
download a file or media from Android / IOS
How to access/download a file or media from Android / IOS using UmbracoApiController as REST API. I tried with
var content = Umbraco.Media(mediaId); foreach (var child in content.Children) { //string url = child.getProperty("umbracoFile").Value.ToString(); medias.Add(child.Url); // this will give Local Url of the media //For examle : - d:\\sampleUmbraco\\media\\2\\Login.jpg } return medias;
How can i download a media as ByteArrayContent using it's id.
Thanks in Advance
Hi Benzeer,
Do you want to press a button and download file from Umbraco ?
You code return just media objects data.
Thanks
Dear Alex,
Thanks for your response. I just want to pass Id to a POST method of a service which will return media as byte array.
I done that Using the following code,
Thanks for your reply.
You are welcome.
Great
is working on a reply...