Ejemplo n.º 1
0
        public void GetDownloadUrl()
        {
            if (!status)
            {
                PutUploadedStatus();
            }
            clientinit();
            Task <HttpResponseMessage> response = client.GetAsync("/asset/" + asset_id + "?timeout=100");
            Task <Download_response>   tfs      = response.Result.Content.ReadAsAsync <Download_response>();

            Assert.IsTrue(response.Result.IsSuccessStatusCode);
            Assert.IsNotNull(tfs.Result);
            Download_response dr = tfs.Result;

            download_url = dr.Download_url;
        }
Ejemplo n.º 2
0
        public IActionResult Get(string id)
        {
            IAmazonS3         s3Client;
            Download_response dr      = new Download_response();
            HttpRequest       request = HttpContext.Request;
            string            query   = request.Query["timeout"].ToString();
            int timeint;

            // If a "timeout" query exists and it can be parsed correctly as a number,
            // apply the timeout value to the expiration timeout of the signed url.
            if (query != null && Int32.TryParse(query, out timeint))
            {
                get_timeout = query;
            }

            try
            {
                if (awsAccessKey == null)
                {
                    initcreds();
                }
                using (s3Client = new AmazonS3Client(awsAccessKey, awsSecretAccessKey, awsregionep))
                {
                    //check Status tag.  If value is not "uploaded", return an error
                    var    tagresult = gets3tag(s3Client, id, "Status");
                    string tagval    = tagresult.Result;
                    if (tagval == null || tagval != "uploaded")
                    {
                        return(NotFound(new ErrorMessage {
                            Error = "File has not been uploaded"
                        }));
                    }
                    string urlString = GeneratePreSignedURL(s3Client, id, "get", get_timeout);
                    dr.Download_url = urlString;
                }
                return(Ok(dr));
            } catch (Exception)
            {
                return(BadRequest());
            }
        }