public async Task <IActionResult> RunUploadTraceAttachment(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "trace/{traceId}/attachments/{fileName}")] HttpRequest req,
            [Blob("images2label", FileAccess.Write, Connection = "TraceStorage")] CloudBlobContainer blobContainerImageToLabel,
            [Blob("mobile", FileAccess.Write, Connection = "TraceStorage")] CloudBlobContainer blobContainerMobile,
            [Blob("gopro", FileAccess.Write, Connection = "TraceStorage")] CloudBlobContainer blobContainerGoPro,
            [AccessToken] AccessTokenResult accessTokenResult,
            string traceId,
            string fileName,
            ILogger log,
            [Blob("manual/{traceId}.json", FileAccess.Read, Connection = "TraceStorage")] Stream traceManualIdJsonFile = null,
            [Blob("mobile/{traceId}.json", FileAccess.Read, Connection = "TraceStorage")] Stream traceMobileIdJsonFile = null,
            [Blob("gopro/{traceId}.json", FileAccess.Read, Connection = "TraceStorage")] Stream traceGoProIdJsonFile   = null
            )
        {
            log.LogInformation("Trace Attachment file");

            if (accessTokenResult.Status != AccessTokenStatus.Valid)
            {
                return(new UnauthorizedResult());
            }

            Stream jsonStream;

            if (traceManualIdJsonFile != null)
            {
                jsonStream = traceManualIdJsonFile;
            }
            else
            {
                if (traceMobileIdJsonFile != null)
                {
                    jsonStream = traceMobileIdJsonFile;
                }
                else
                {
                    if (traceGoProIdJsonFile != null)
                    {
                        jsonStream = traceGoProIdJsonFile;
                    }
                    else
                    {
                        return(new UnauthorizedResult());
                    }
                }
            }
            var            trace   = await new StreamReader(jsonStream).ReadToEndAsync();
            TraceViewModel traceVm = JsonSerializer.Deserialize <TraceViewModel>(trace);

            //ecrire dans le bon blob
            string         name                = string.Empty;
            Guid           mediaId             = Guid.NewGuid();
            CloudBlockBlob traceAttachmentBlob = null;
            string         extension           = Path.GetExtension(fileName);

            if (traceVm.trackingMode.ToLower() == "manual")
            {
                name = await GetNextFileName(blobContainerImageToLabel, traceId, extension);

                traceAttachmentBlob = blobContainerImageToLabel.GetBlockBlobReference(name);
            }
            if (traceVm.trackingMode.ToLower() == "automatic")
            {
                name = await GetNextFileName(blobContainerMobile, traceId, extension);

                traceAttachmentBlob = blobContainerMobile.GetBlockBlobReference(name);
            }
            if (traceVm.trackingMode.ToLower() == "gopro")
            {
                name = await GetNextFileName(blobContainerGoPro, traceId, extension);

                traceAttachmentBlob = blobContainerGoPro.GetBlockBlobReference(name);
            }

            traceAttachmentBlob.Properties.ContentType = req.ContentType;
            traceAttachmentBlob.Metadata.Add("uid", accessTokenResult.User.Id);
            traceAttachmentBlob.Metadata.Add("mediaId", mediaId.ToString());
            await traceAttachmentBlob.UploadFromStreamAsync(req.Body);

            // Add to Media
            try
            {
                await _mediaStore.AddMedia(mediaId, name, accessTokenResult.User.Id, traceId, DateTime.UtcNow, traceAttachmentBlob.Uri);

                ImageLabel imageToInsert = new ImageLabel(Guid.NewGuid(), Guid.Parse(accessTokenResult.User.Id), DateTime.Now, name, string.Empty, string.Empty, string.Empty, traceAttachmentBlob.Uri.AbsoluteUri);
                if (traceVm.trackingMode.ToLower() == "manual")
                {
                    await _imageService.InsertImageData(imageToInsert);
                }
            }
            catch (Exception e)
            {
                log.LogError(e, "Unable to store media to DB");
            }

            return(new StatusCodeResult(200));
        }