Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Benzeer 3 posts 106 karma points
    Aug 05, 2015 @ 06:14
    Benzeer
    0

    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

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Aug 05, 2015 @ 12:53
    Alex Skrypnyk
    0

    Hi Benzeer,

    Do you want to press a button and download file from Umbraco ?

    You code return just media objects data.

    Thanks

  • Benzeer 3 posts 106 karma points
    Aug 05, 2015 @ 12:58
    Benzeer
    103

    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,

      [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;
        }
    

    Thanks for your reply.

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Aug 05, 2015 @ 12:59
    Alex Skrypnyk
    0

    You are welcome.

    Great

Please Sign in or register to post replies

Write your reply to:

Draft