Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Make sure Visual Studio is closed the first time you run these scripts. The firs
- Fixed put '/submodels/{submodelIdentifier}' endpoint to replace submodel instead of update the submodel (SubmodelRepositoryController)
- Fixed Submodel element serialization to write `valueType` property tp use XSD data type definition (SubmodelElementConverter)
- The processing of values for Boolean properties has been corrected when these are provided as strings via the REST API. The return format for Boolean values via the REST API has been improved (upper- / lower-case).
- Fix the set of file names and values if the attachment is posted, deleted or put to a file sub-model element.

## Features
- Add Submodel Registry HTTP Server (SubmodelRegistryHttpServer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -927,26 +927,28 @@ public async Task<IActionResult> PutFileByPath(string idShortPath, IFormFile fil

if (fileElementRetrieved.Entity.ModelType != ModelType.File)
{
Result result = new Result(false, new ErrorMessage($"ModelType of {idShortPath} is not File but {fileElementRetrieved.Entity.ModelType}"));
var result = new Result(false, new ErrorMessage($"ModelType of {idShortPath} is not File but {fileElementRetrieved.Entity.ModelType}"));
return result.CreateActionResult(CrudOperation.Retrieve);
}

IFileElement fileElement = fileElementRetrieved.Entity.Cast<IFileElement>();
var fileElement = fileElementRetrieved.Entity.Cast<IFileElement>();

// keep existing path if available, otherwise set path to uploaded file name
string fileName;
if (fileElement.Value.Value != null)
fileName = fileElement.Value.Value.TrimStart('/');
else
// Delete existing file if any
if (!string.IsNullOrEmpty(fileElement.Value.Value))
{
fileName = file.FileName;
fileElement.Value.Value = "/" + fileName.Replace("\\", "/");
var fileProvider = hostingEnvironment.ContentRootFileProvider;
var existingFile = fileProvider.GetFileInfo(fileElement.Value.Value.TrimStart('/'));
if (existingFile.Exists && !string.IsNullOrEmpty(existingFile.PhysicalPath))
System.IO.File.Delete(existingFile.PhysicalPath);
}

var fileName = file.FileName;
fileElement.Value.Value = "/" + fileName.Replace("\\", "/");

var filePath = Path.Combine(hostingEnvironment.ContentRootPath, fileName);

Directory.CreateDirectory(Path.GetDirectoryName(filePath));
using (var stream = System.IO.File.Create(filePath))
await using (var stream = System.IO.File.Create(filePath))
{
await file.CopyToAsync(stream);
}
Expand Down Expand Up @@ -976,20 +978,22 @@ public IActionResult DeleteFileByPath(string idShortPath)

if (fileElementRetrieved.Entity.ModelType != ModelType.File)
{
Result result = new Result(false, new ErrorMessage($"ModelType of {idShortPath} is not File but {fileElementRetrieved.Entity.ModelType}"));
var result = new Result(false, new ErrorMessage($"ModelType of {idShortPath} is not File but {fileElementRetrieved.Entity.ModelType}"));
return result.CreateActionResult(CrudOperation.Retrieve);
}

IFileElement fileElement = fileElementRetrieved.Entity.Cast<IFileElement>();
string fileName = fileElement.Value.Value.TrimStart('/');
var fileElement = fileElementRetrieved.Entity.Cast<IFileElement>();
var fileName = fileElement.Value.Value.TrimStart('/');

IFileProvider fileProvider = hostingEnvironment.ContentRootFileProvider;
var fileProvider = hostingEnvironment.ContentRootFileProvider;
var file = fileProvider.GetFileInfo(fileName);

if (file.Exists && !string.IsNullOrEmpty(file.PhysicalPath))
System.IO.File.Delete(file.PhysicalPath);
else
return NotFound(new { message = "Physical file not found", itemId = file.PhysicalPath });

fileElement.Value.Value = string.Empty;

return Ok();
}
Expand Down