public IActionResult Post() { IAmazonS3 s3Client; Filestore fs = new Filestore(); // Generate UUID/Asset-id Guid g = Guid.NewGuid(); // TODO: should issue a GET to check for name collision on "asset-id" (which should almost never happen) fs.id = g.ToString(); try { if (awsAccessKey == null) { initcreds(); } // Get a s3 signed url using (s3Client = new AmazonS3Client(awsAccessKey, awsSecretAccessKey, awsregionep)) { string urlString = GeneratePreSignedURL(s3Client, fs.id, "put"); fs.upload_url = urlString; } // Wrap the signed url in a query parameter attached to a POST URL for this app string localurl = HttpContext.Request.Host.Value; string scheme = HttpContext.Request.Scheme; fs.upload_url = scheme + "://" + localurl + "/asset/" + fs.id + "?redir=" + WebUtility.UrlEncode(fs.upload_url); return(Ok(fs)); } catch (Exception) { return(StatusCode((int)HttpStatusCode.InternalServerError)); } }
public void PostGetURL() { testinit(); clientinit(); Task <HttpResponseMessage> response = client.PostAsync("/asset", null); Assert.IsTrue(response.Result.IsSuccessStatusCode); Task <Filestore> tfs = response.Result.Content.ReadAsAsync <Filestore>(); Assert.IsNotNull(tfs.Result); Filestore fs = tfs.Result; upload_url = fs.upload_url; asset_id = fs.id; }