예제 #1
0
        public async Task <File> AttachToExistingFile(string storageService, string storageId, string asUserKey = null, string bearerToken = null, bool logToConsole = true)
        {
            var fileKey = GenerateKey("file");
            var request = new AttachToExistingFileRequest()
            {
                Name = fileKey, StorageService = storageService, StorageId = storageId
            };

            var newFile = await Put <AttachToExistingFileRequest, File>(request, $"files/{fileKey}/attach", asUserKey, bearerToken);

            if (logToConsole)
            {
                Console.WriteLine($"Attached to Existing File: Key='{newFile.Key}', StorageService='{storageService}', StorageId='{storageId}'");
            }
            ;
            return(newFile);
        }
예제 #2
0
        public async Task <IActionResult> AttachToExistingFile(string fileKey, [FromBody] AttachToExistingFileRequest request)
        {
            try
            {
                var userKey           = _contextAccessor.UserKeyFromContext();
                var storageId         = request.StorageId;
                var createFileRequest = new CreateFileRequest()
                {
                    Key = fileKey, Name = request.Name, StorageService = request.StorageService
                };

                var newFile = await _hiarcDatabase.CreateFile(createFileRequest, userKey, storageId);

                var uri = $"{_hiarcSettings.BaseUri}/files/{newFile.Key}";
                return(Created(uri, newFile));
            }
            catch (Exception ex)
            {
                return(BuildErrorResponse(ex, _logger));
            }
        }