public async Task <IActionResult> RunUploadTrace(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "trace")] HttpRequest req,
            [Blob("manual", FileAccess.Write, Connection = "TraceStorage")] CloudBlobContainer blobContainerManual,
            [Blob("mobile", FileAccess.Write, Connection = "TraceStorage")] CloudBlobContainer blobContainerMobile,
            [Blob("gopro", FileAccess.Write, Connection = "TraceStorage")] CloudBlobContainer blobContainerGoPro,
            [AccessToken] AccessTokenResult accessTokenResult,
            ILogger log
            )
        {
            log.LogInformation("Trace file");
            if (accessTokenResult.Status != AccessTokenStatus.Valid)
            {
                return(new UnauthorizedResult());
            }
            var            body    = await new StreamReader(req.Body).ReadToEndAsync();
            TraceViewModel traceVm = JsonSerializer.Deserialize <TraceViewModel>(body);

            /// Backup trace to storage account
            string name = $"{traceVm.id}.json";

            CloudBlockBlob         traceAttachmentBlob = blobContainerManual.GetBlockBlobReference(name);
            SharedAccessBlobPolicy sharedAccessPolicy  = new SharedAccessBlobPolicy()
            {
                Permissions = SharedAccessBlobPermissions.Add | SharedAccessBlobPermissions.Create |
                              SharedAccessBlobPermissions.Write,
                SharedAccessExpiryTime = DateTimeOffset.Now.AddMinutes(20)
            };
            string sas = blobContainerManual.GetSharedAccessSignature(sharedAccessPolicy);

            if (traceVm.trackingMode.ToLower() == "automatic")
            {
                traceAttachmentBlob = blobContainerMobile.GetBlockBlobReference(name);
                sas = blobContainerMobile.GetSharedAccessSignature(sharedAccessPolicy);
            }
            if (traceVm.trackingMode.ToLower() == "gopro")
            {
                traceAttachmentBlob = blobContainerGoPro.GetBlockBlobReference(name);
                sas = blobContainerMobile.GetSharedAccessSignature(sharedAccessPolicy);
            }

            traceAttachmentBlob.Properties.ContentType = "application/json";
            traceAttachmentBlob.Metadata.Add("uid", accessTokenResult.User.Id);
            await traceAttachmentBlob.UploadTextAsync(body);

            // Insert it into PGSQL
            try
            {
                await _traceService.AddTrace(accessTokenResult.User.Id, traceVm);

                await _traceService.AddTrajectoryPoints(traceVm);
            }
            catch (Exception e)
            {
                log.LogError(e, "Unable to store media to DB");
            }

            return(new OkObjectResult(new
            {
                traceId = traceVm.id,
                uploadUri = $"{traceAttachmentBlob.Uri.AbsoluteUri}{sas}"
            }));
        }